我只有一小段代码可以显示包含某些细节的邮件视图,并且在调用时
[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];
由于
答案 0 :(得分:3)
在创建MFMailComposeViewController
之前,请务必通过添加
if ([MFMailComposeViewController canSendMail]) {
//Place your code here to create the controller and present
}
如果您尝试在尚未设置邮件的设备上显示MFMailComposeViewController
,则该应用会崩溃。添加此条件将检测到此情况。
希望这会有所帮助......
答案 1 :(得分: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];
}