【发布时间】:2016-05-04 17:58:10
【问题描述】:
我的 iPhone 应用程序被 TestFlight 拒绝,因为它使 iPad 崩溃。有问题的代码试图显示一个用于发送电子邮件的控制器。我已将代码简化为一个小而简单的示例,该示例在运行 iOS 9.3.1 的 iPhone 5c 上按预期工作,但运行 iOS 9.3.1 的 iPad 2 崩溃:
- (void)viewDidLoad {
[super viewDidLoad];
[self displayComposerSheet];
}
-(void)displayComposerSheet {
// Create e-mail interface
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"iPad crash test"];
// Add recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"email@somewhere.com"];
[picker setToRecipients:toRecipients];
// Fill body
NSString *emailBody = @"A short test of iPad crashes";
[picker setMessageBody:emailBody isHTML:NO];
// Show interface - iPad crashes here but iPhone is ok
[self presentViewController:picker animated:YES completion:nil];
}
错误信息是:
*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图在目标上呈现 nil 模态视图控制器。”
我花了一些时间来解决这个问题,但一直无法解决。任何想法或建议将不胜感激!
【问题讨论】:
-
是
pickernil?阅读MFMailComposeViewController的文档。在尝试使用此类之前,您需要检查设备是否可以发送电子邮件。
标签: objective-c iphone ipad presentviewcontroller