我試圖使用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