未设置邮件帐户时,应用程序随机崩溃。有时,我收到错误警报。请帮我。
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];
}