我正在创造
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
Run Code Online (Sandbox Code Playgroud)
但由于未捕获的异常'NSInvalidArgumentException',应用程序因错误终止应用程序而导致应用程序崩溃且应用程序崩溃,原因:'Application tried to present a nil modal view controller on target.它在模拟器中工作正常,但在Device中崩溃.如何使用MFMailComposerViewControllerIOS 7.
Yau*_*nka 13
您应该检查MFMailComposeViewController是否能够在尝试发送之前发送您的邮件(例如,用户在iOS设备上没有任何邮件帐户).
在您的Objective-C案例中:
MFMailComposeViewController *myMailCompose = [[MFMailComposeViewController alloc] init];
if ([MFMailComposeViewController canSendMail]) {
myMailCompose.mailComposeDelegate = self;
[myMailCompose setSubject:@"Subject"];
[myMailCompose setMessageBody:@"message" isHTML:NO];
[self presentViewController:myMailCompose animated:YES completion:nil];
} else {
// unable to send mail, notify your users somehow
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特3:
let myMailCompose = MFMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
myMailCompose.mailComposeDelegate = self
myMailCompose.setSubject("Subject")
myMailCompose.setMessageBody("message", isHTML: false)
self.present(myMailCompose, animated: true, completion: nil)
} else {
// unable to send mail, notify your users somehow
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3218 次 |
| 最近记录: |