应用程序试图介绍MFMailComposeViewController时会崩溃



我试图在我的应用程序中介绍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;
        }
    }

请在您的代码中检查以下行:

[controller addAttachmentData:myData mimeType:@"image/png" fileName:[NSString stringWithFormat:@"%@",ImageToShare]];

在那里,将[NSString stringWithFormat:@"%@",ImageToShare]替换为一些文本或图像名称,因为ImagetoShare是图像的对象

然后看起来像:

[controller addAttachmentData:myData mimeType:@"image/png" fileName:"YourImageFileName"]; 

请更换行:

[self presentModalViewController:controller animated:YES];

[self presentViewController:controller animated:YES completion:nil];

最新更新