Ios 尝试呈现MFMailComposeViewController时应用程序崩溃
我试图在我的应用程序中呈现MFMailComposeViewController,以便从我的应用程序发送邮件。每当我调用方法来呈现mail composer时,我的应用程序都会崩溃,崩溃日志如下:Ios 尝试呈现MFMailComposeViewController时应用程序崩溃,ios,mfmailcomposeviewcontroller,rgba,Ios,Mfmailcomposeviewcontroller,Rgba,我试图在我的应用程序中呈现MFMailComposeViewController,以便从我的应用程序发送邮件。每当我调用方法来呈现mail composer时,我的应用程序都会崩溃,崩溃日志如下: Assertion failure in -[UICGColor encodeWithCoder:], /SourceCache/UIKit/UIKit-2372/UIColor.m:1191 Terminating app due to uncaught exception 'NSInternal
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;
}
}
请检查代码中的以下行:
[controller addAttachmentData:myData mimeType:@"image/png" fileName:[NSString stringWithFormat:@"%@",ImageToShare]];
由于ImageToShare是图像的对象,因此将[NSString stringWithFormat:@“%@”,ImageToShare]替换为一些文本或图像名称
然后它看起来像:
[controller addAttachmentData:myData mimeType:@"image/png" fileName:"YourImageFileName"];
及
请更换线路:
[self presentModalViewController:controller animated:YES];
与
你能分享代码吗?您是否复制和粘贴此内容不正确,在关闭之前缺少一个“关闭”。NSString*msgBody=[NSString stringWithFormat:@“%@,签出];您是否在代码中的任何位置使用了ColorWithPatternImage?@iCodeForFood我已经评论过代码仍然不起作用。:)@Ashu如果您评论过关于附件文件的所有行,这仍然不起作用?
[self presentViewController:controller animated:YES completion:nil];