【发布时间】:2015-03-08 16:54:14
【问题描述】:
我正在尝试使用 FMailComposeViewController 发送电子邮件。当我尝试通过调用 presentModalViewController 发送邮件时,应用程序崩溃。在 emulateR 中,它一直在设备上崩溃,它崩溃了一半时间。
我没有收到错误消息,但应用程序冻结并且调试器显示它正在 int main(int argc, char * argv[]) { @autoreleasepool { 返回 UIApplicationMain(argc, argv, nil, 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:@"tedpottel@yahoo.com"]];
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: %@", result==MFMailComposeResultCancelled?@"Cancelled":
result==MFMailComposeResultSaved?@"Saved":
result==MFMailComposeResultSent?@"Sent":
result==MFMailComposeResultFailed?@"Failed":@"Unknown");
}
【问题讨论】:
-
请使用您在控制台中看到的错误消息更新帖子。
-
你在模拟器上测试吗?我已经看到它在模拟器上很不稳定。在真实设备上进行测试。也尝试使用
[self presentViewController]
标签: ios