muyoungko
muyoungko

Reputation: 83

App crashed using MFMailComposeViewController

I get this crash on iOS 7,

Assertion failed: (result == KERN_SUCCESS), function + [XPCMachSendRight wrapSendRight:], file /SourceCache/XPCObjects/XPCObjects-46/XPCMachSendRight.m, line27.

Steps which lead to this crash are,

  1. Opening MFMailComposeViewController
  2. Press home button
  3. App crashed.

Here is crash report,

Thread 0 Crashed:
0   libsystem_kernel.dylib          0x393bf1fc 0x393ac000 + 78332
1   libsystem_pthread.dylib         0x39426a4f 0x39423000 + 14927
2   libsystem_c.dylib               0x39370083 0x39326000 + 303235
3   libsystem_c.dylib               0x39370035 0x39326000 + 303157
4   libsystem_c.dylib               0x3934fc67 0x39326000 + 171111
5   XPCObjects                      0x375a7905 0x375a2000 + 22789
6   UIKit                           0x317b41f9 0x3128d000 + 5403129
7   UIKit                           0x31529d45 0x3128d000 + 2739525
8   QuartzCore                      0x30f54af9 0x30f13000 + 269049
9   QuartzCore                      0x30f1b077 0x30f13000 + 32887
10  QuartzCore                      0x30f1ae1b 0x30f13000 + 32283
11  UIKit                           0x31318deb 0x3128d000 + 572907
12  UIKit                           0x31318d53 0x3128d000 + 572755
13  CoreFoundation                  0x2eaddf6f 0x2ea3e000 + 655215
14  CoreFoundation                  0x2eadb8fb 0x2ea3e000 + 645371
15  CoreFoundation                  0x2eadbbb5 0x2ea3e000 + 646069
16  CoreFoundation                  0x2ea4653d 0x2ea3e000 + 34109
17  CoreFoundation                  0x2ea4631f 0x2ea3e000 + 33567
18  GraphicsServices                0x337762e7 0x3376f000 + 29415
19  UIKit                           0x312fd1e1 0x3128d000 + 459233
20  MYAPP                           0x0002d5c9 main (main.mm:18)
21  MYAPP                           0x0002d524 start + 36

I found similar problem mentioned here: app get crashed while navigating to RootViewController from Message popup

Crash occurs rarely. I don't know what [XPCMachSendRight wrapSendRight:] this is and how to prevent it from crashing my app?

Upvotes: 0

Views: 570

Answers (1)

Kiran Gaware
Kiran Gaware

Reputation: 122

Before using MFMailComposeViewController class, you must always check to see if the current device is configured to send email at all using the canSendMail method. If the user’s device is not set up for the delivery of email, you can notify the user or simply disable the email dispatch features in your application. You should not attempt to use this interface if the canSendMail method returns NO.

Use this code....

if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"A Message from Bloomingkids"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
[mailer setToRecipients:toRecipients];
UIImage *myImage = [UIImage imageNamed:@"bloomingKidsLogo.png"];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"Images"];
NSString *emailBody = @"Have you seen the Bloomingkids web site?";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                message:@"Your device doesn't     support     the composer sheet"
                                               delegate:nil
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles: nil];
[alert show];
}

Add any email account in your device first means setup an email account...

Upvotes: 3

Related Questions