我试图使用FMailComposeViewController发送电子邮件。当我尝试通过调用presentModalViewController发送邮件时,应用程序崩溃。在仿真R中,它在设备上的所有时间都会崩溃,只有一半时间会崩溃。试图发送邮件和应用程序崩溃
我没有得到一个错误消息,但应用程序冻结和debuuger表明它打算 INT主(INT ARGC,CHAR *的argv []){ @autoreleasepool { 回报UIApplicationMain(ARGC,ARGV,零, NSStringFromClass([AppDelegate class])); } } 应用程序总是在模拟器中崩溃,大约有一半时间在iPhone上。
代码:
- (IBAction)aEmail:(id)sender {
if([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *mailCtrl = [[MFMailComposeViewController alloc] init];
[mailCtrl setSubject:@"Your TellaFortune Card Reading"];
[mailCtrl setToRecipients:[NSArray arrayWithObject:@"[email protected]"]];
mailCtrl.mailComposeDelegate = self;
[mailCtrl setMessageBody: @"hello" isHTML: false];
// CRASHES ON THID LINE
[self presentModalViewController:mailCtrl animated:NO];
// [mailCtrl release];
}
else
{
UIAlertView *alert=[[ UIAlertView alloc]
initWithTitle:@"Cannot send email"
message: @"Please check internet connection and email set up"
delegate: self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[alert show];
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// if you do not have thid methed when sending emsil, app will freez after
// sent or cancel button has been pressed.
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Email result: %@", [email protected]"Cancelled":
[email protected]"Saved":
[email protected]"Sent":
[email protected]"Failed":@"Unknown");
}
请更新您在控制台中看到的错误消息。 – 2015-03-08 17:15:39
你在模拟器上测试吗?我已经看到它在模拟器上不可思议。在真实的设备上进行测试。也可以尝试使用'[self presentViewController]' – soulshined 2015-03-08 19:46:34