gpt4 book ai didi

ios7 - IOS : Application tried to present a nil modal view controller on target

转载 作者:行者123 更新时间:2023-12-03 09:13:38 27 4
gpt4 key购买 nike

我正在开发一个应用程序,要求是在 UIAlertView 的按钮单击上打开电子邮件编写器。

电子邮件消息正文中的消息是从 UITextView 复制的。我正在使用以下代码片段:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
{
// opening message composer
}
else
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Test mail"];
[picker setMessageBody:messageBody.text isHTML:YES];
[self presentViewController:picker animated:YES completion:NULL];
}
}
// mail compose delegate
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:NULL];
}

但问题是我收到错误消息说应用程序试图在目标上呈现一个 nil 模态视图 Controller 。我们如何在 ios 7 中打开默认邮件编辑器?

最佳答案

根据 Apple,您应该检查 MFMailComposeViewController 能够在发送之前发送您的邮件

if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Test mail"];
[picker setMessageBody:messageBody.text isHTML:YES];
[self presentViewController:picker animated:YES completion:NULL];
}

swift :
if MFMailComposeViewController.canSendMail() else {
// Send mail code
}

引用 : Apple Dev url

关于ios7 - IOS : Application tried to present a nil modal view controller on target,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19239056/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com