0

我只有一小段代码应该显示包含某些详细信息的邮件视图,并且在调用时

 [self presentViewController:controller animated:YES completion:NULL];

应用程序崩溃,说Thread 1: breakpoint 1.1

我不确定是什么导致了这次崩溃。我在下面提供代码。

NSString* encryptedText = [self getEncryptedText:noteText.text :cipherField.text];

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; controller.mailComposeDelegate = (id)self;

[controller setSubject:titleField.text];
[controller setMessageBody:encryptedText isHTML:NO];

[self presentViewController:controller animated:YES completion:NULL];

谢谢

4

2 回答 2

3

在创建之前,请MFMailComposeViewController确保通过添加检查用户是否已在其设备上设置了邮件

if ([MFMailComposeViewController canSendMail]) {

    //Place your code here to create the controller and present

}

如果您尝试MFMailComposeViewController在尚未设置邮件的设备上显示 a,则应用程序将崩溃。添加此条件将检测到这一点。

希望这可以帮助...

于 2014-07-19T10:52:33.803 回答
1

试试这个代码。

if ([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
        [composeViewController setMailComposeDelegate:self];
        [composeViewController setToRecipients:@[@""]];
        [composeViewController setSubject:@"Hi Test"];
        [composeViewController setMessageBody:@"Hello Test" isHTML:YES];

        [self presentViewController:composeViewController animated:YES completion:nil];

    }
于 2014-07-19T10:52:50.000 回答