应用程序试图在iOS 10中的目标上呈现一个无模式视图控制器?
问题描述:
我在我的应用程序中实现了MFMailComposeViewController,当我点击我的邮件按钮时,我得到了下面的错误。应用程序试图在iOS 10中的目标上呈现一个无模式视图控制器?
应用程序试图在目标强大的文本呈现零模态视图控制器
这里是我的代码:
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.navigationBar.tintColor = [UIColor blackColor];
[mailComposer.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor blackColor]}];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:@"Co - Contact Us"];
[mailComposer setToRecipients:@[@"[email protected]"]];
NSString *supportText = @"Enter your comment here:\n\n\n\n\n";
supportText = [supportText stringByAppendingString:[NSString stringWithFormat:@"iOS Version: %@\nCorner Version:%@\nBuild:%@\n\n",iOSVersion,version, build]];
[mailComposer setMessageBody:supportText isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
这有什么错我的代码。请帮忙
答
如果设备没有配置邮件或使用模拟器会导致崩溃或异常。
mailComposer = [[MFMailComposeViewController alloc] init];
上面的代码行可能会导致问题。在模拟器初始化方法中可能会返回NULL
或nil
。
,只需检查canSendMail
呈现模式的viewController前:
一样,
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
mailComposer = [[MFMailComposeViewController alloc]init];
if ([MFMailComposeViewController canSendMail] && mailComposer) {
mailComposer.navigationBar.tintColor = [UIColor blackColor];
[mailComposer.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:@"Corner - Contact Us"];
[mailComposer setToRecipients:@[@"[email protected]"]];
NSString *supportText = @"Enter your comment here:\n\n\n\n\n";
supportText = [supportText stringByAppendingString:[NSString stringWithFormat:@"iOS Version: %@\nCorner Version:%@\nBuild:%@\n\n",iOSVersion,version, build]];
[mailComposer setMessageBody:supportText isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
}
为MFMailcomposerViewController @visible接口声明的选择 'canSendMail' 我收到此错误 –
尝试编辑答案,有错别字错误@ User558 –
我试过了,但它没有进入IF循环 –