未设置邮件帐户时应用程序崩溃

时间:2018-04-27 09:18:31

标签: objective-c mfmailcomposeviewcontroller uialertviewcontroller

当未设置邮件帐户时,应用程序会随机崩溃。有时,我收到错误警报。请帮帮我。

if ([MFMailComposeViewController canSendMail]) {

        MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
        mc.mailComposeDelegate = self;
        [mc addAttachmentData:myData mimeType:@"application/pdf" fileName:@"myPdf2.pdf"];
        [self presentViewController:mc animated:YES completion:NULL];
    }

    else {

        UIAlertController * alert = [UIAlertController
                                     alertControllerWithTitle:@"Alert"
                                     message:@"Please set up your mail account!"
                                     preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction* okButton = [UIAlertAction
                                    actionWithTitle:@"OK"
                                    style:UIAlertActionStyleDefault
                                    handler:^(UIAlertAction * action) {
                                        //Handle your yes please button action here

                                    }];
        [alert addAction:okButton];
        [self presentViewController:alert animated:YES completion:nil];
    }

0 个答案:

没有答案