objective-c – 应用程序在IOS7中的MFMailComposeViewController对象上崩溃

objective-c – 应用程序在IOS7中的MFMailComposeViewController对象上崩溃,第1张

概述我正在创造 MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 但是选择器是nil而且应用程序崩溃并且因为未捕获的异常’NSInvalidArgumentException’而终止应用程序,原因:’应用程序尝试在目标上显示nil模态视图控制器.它在模拟器中工作正常,但在Device中崩溃 我正在创造

MFMailComposeVIEwController *picker = [[MFMailComposeVIEwController alloc] init];

但是选择器是nil而且应用程序崩溃并且因为未捕获的异常’NSinvalidargumentexception’而终止应用程序,原因:’应用程序尝试在目标上显示nil模态视图控制器.它在模拟器中工作正常,但在Device中崩溃.
如何在IOS 7中使用MFMailComposerVIEwController.

解决方法 您应该检查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}

斯威夫特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}
总结

以上是内存溢出为你收集整理的objective-c – 应用程序在IOS7中的MFMailComposeViewController对象上崩溃全部内容,希望文章能够帮你解决objective-c – 应用程序在IOS7中的MFMailComposeViewController对象上崩溃所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1081411.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存