-1

I am trying to present MFMailComposeViewController in my application to send mail from my application. Whenever I call the method to present mail composer my application crashes with below crash log:

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

Below is the code I am using:

// 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;
        }

    }
Ashutosh
  • 2,215
  • 14
  • 27

1 Answers1

0

Please check following line in your code:

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

there replace [NSString stringWithFormat:@"%@",ImageToShare] with some text or image name as ImageToShare is an object of image

Then it looks like:

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

AND

Please replace line:

[self presentModalViewController:controller animated:YES];

with

[self presentViewController:controller animated:YES completion:nil];
Flexo
  • 87,323
  • 22
  • 191
  • 272
Sandip Patel - SM
  • 3,346
  • 29
  • 27