MailCompositionService意外退出ios

时间:2016-09-05 09:30:42

标签: ios objective-c xcode mfmailcomposeviewcontroller

我是新手,

我在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];
}

但是当我点击控制器中的发送按钮时,我收到错误,

  

2016-09-05 14:55:24.488 mailDemo [1276:104171]   viewServiceDidTerminateWithError:错误   Domain = _UIViewServiceInterfaceErrorDomain Code = 3“(null)”   UserInfo = {Message = Service Connection Interrupted} 2016-09-05   14:55:24.989 mailDemo [1276:104171]试图驳回演示文稿   控制器在转换时已经。   (< _UIFullscreenPresentationController:0x7fe35b52d2a0>)2016-09-05   14:55:24.991 mailDemo [1276:104171] transitionViewForCurrentTransition   未设置,演示控制器在期间被解雇   介绍? (< _UIFullscreenPresentationController:0x7fe35b52d2a0>)

问题是什么?

3 个答案:

答案 0 :(得分:2)

您的代码没有任何问题。MFMailComposeViewController不适用于模拟器,请在实际设备中尝试相同的代码。

答案 1 :(得分:1)

模拟器不支持方法和设备不登录邮件,这种方法没有任何响应。

替换此方法::

- (void)sendMail:(id)sender {


    if (![MFMailComposeViewController canSendMail]) {
        NSLog(@"Mail services are not available.");
        return;
    }
    else{
            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];
        }
}

答案 2 :(得分:0)

MFMailComposeViewController不适用于模拟器。如果您在真实设备中尝试相同的代码,它将起作用。您的代码没有任何问题。