KAR KAR - 11 months ago 109
iOS Question

MailCompositionService quit unexpectedly ios

I am new to this,

I have this code in my viewController,

- (void)sendMail:(id)sender {
NSArray *to = [NSArray arrayWithObjects:@"rayjada11@gmail.com", nil];

mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setToRecipients:to];
[mailComposer setSubject:@"Test Mail"];
[mailComposer setMessageBody:@"Testing message body" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];

#pragma mark - mail compose delegate
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if(result) {
NSLog(@"Result = %d", result);
if(error) {
NSLog(@"Error = %@", error);
[self dismissModalViewControllerAnimated:YES];

But when I click send button in my controller, I am getting error like,

2016-09-05 14:55:24.488 mailDemo[1276:104171]
viewServiceDidTerminateWithError: Error
Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)"
UserInfo={Message=Service Connection Interrupted} 2016-09-05
14:55:24.989 mailDemo[1276:104171] Trying to dismiss the presentation
controller while transitioning already.
(<_UIFullscreenPresentationController: 0x7fe35b52d2a0>) 2016-09-05
14:55:24.991 mailDemo[1276:104171] transitionViewForCurrentTransition
is not set, presentation controller was dismissed during the
presentation? (<_UIFullscreenPresentationController: 0x7fe35b52d2a0>)

What is the issue?

Answer Source

There is nothing wrong with your code.MFMailComposeViewController is not work for simulator, Try same code in real device.