我正在尝试在我的应用程序中显示MFMailComposeViewController以从我的应用程序发送邮件。每当我调用该方法来呈现邮件编写器时,我的应用程序就会崩溃,崩溃日志如下:
Assertion failure in -[UICGColor encodeWithCoder:], /SourceCache/UIKit/UIKit-2372/UIColor.m:1191
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only support RGBA or the White color space, this method is a hack.'
First throw call stack:
(0x391e63e7 0x36719963 0x391e629d 0x33da07b3 0x337d6c5f 0x33d435c7 0x33d42e71 0x339099cb 0x33908d1b 0x391e3757 0x33908a95 0x339e664d 0x33974e83 0x33974d17 0x3927a80f 0x33974c0b 0x3397e261 0x3927858b 0x3397e23b 0x39277793 0x3927ab3b 0x3927867d 0x3927b613 0x3927b7d9 0x3a2397f1 0x3a239684)
libc++abi.dylib: terminate called throwing an exception
以下是我正在使用的代码:
// Send email
- (void) emailAction
{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"FavePlates app"];
UIImage *ImageToShare = selectedDishImageView.image;
NSData *myData = UIImagePNGRepresentation(ImageToShare);
[controller addAttachmentData:myData mimeType:@"image/png" fileName:[NSString stringWithFormat:@"%@",ImageToShare]];
NSString * msgBody = [NSString stringWithFormat:@"%@", Check Out];
[controller setMessageBody:msgBody
isHTML:NO];
if (controller) {
[self presentModalViewController:controller
animated:YES];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
NSString *messageBody= [[NSString alloc] init];
switch (result)
{
case MFMailComposeResultCancelled:
DLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
[self dismissViewControllerAnimated:YES
completion:nil];
messageBody = @"You cancelled sending message";
break;
case MFMailComposeResultSaved:
DLog(@"Mail saved: you saved the email message in the drafts folder.");
[self dismissViewControllerAnimated:YES
completion:nil];
messageBody = @"Mail saved: you saved the email message in the drafts folder'";
break;
case MFMailComposeResultSent:
DLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
[self dismissViewControllerAnimated:YES
completion:nil];
messageBody = @"Mail has been sent";
[self mailSent];
break;
case MFMailComposeResultFailed:
DLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
[self dismissViewControllerAnimated:YES
completion:nil];
messageBody = @"Email sending failed";
break;
default:
DLog(@"Mail not sent.");
[self dismissViewControllerAnimated:YES
completion:nil];
break;
}
}
答案 0 :(得分:0)
请检查代码中的以下行:
[controller addAttachmentData:myData mimeType:@"image/png" fileName:[NSString stringWithFormat:@"%@",ImageToShare]];
将[NSString stringWithFormat:@"%@",ImageToShare]
替换为一些文字或图像名称,因为ImageToShare是图像对象
然后它看起来像:
[controller addAttachmentData:myData mimeType:@"image/png" fileName:"YourImageFileName"];
AND
请替换行:
[self presentModalViewController:controller animated:YES];
带
[self presentViewController:controller animated:YES completion:nil];