我正在开发一个可在所有部署目标模拟器(5.0-6.1)和我的iPhone 3GS,4,4S和第2代iPad上运行的应用程序。今天我有机会尝试在iPad Mini上运行它。我在任何地方都工作,除非我尝试使用MFMailComposeViewController对象来发送电子邮件,这会导致它因异常而崩溃。
我直接使用MailComposer示例项目中的代码,但它在调用presentModalViewController:animated:时总是崩溃。所以我尝试了presentViewController:animated:completion:因为其他方法已被弃用,但它仍然不起作用。
我链接到MessageUI.framework导入了类:
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
委托已设置。这是代码:
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Contact Email"];
// Set up recipient
NSArray *toRecipients = [NSArray arrayWithObject:@"info@foo.bar"];
[picker setToRecipients:toRecipients];
// [self presentModalViewController:picker animated:YES];
[self presentViewController:picker animated:YES completion:NULL];
}
iPad Mini可能存在导致此问题的错误吗?我没有任何其他可以试用的新设备所以我不确定它是迷你问题还是更大的问题。任何帮助都会受到赞赏,因为我已准备好向Apple提交,但我确实不想用崩溃的bug来做到这一点。
答案 0 :(得分:1)
尝试使用
包装MFMailComposeViewController代码if ( [MFMailCompseViewController canSendMail])
我猜这个设备上没有邮件设置。
答案 1 :(得分:1)
可能没有设置邮件帐户或因某些其他原因无法发送电子邮件。
请务必先调用MFMailComposeViewController的+ (BOOL)canSendMail
功能。