Reputation: 6983
I'm trying to use FMailComposeViewController to send a email message. When I try to send the mail by calling presentModalViewController the app crashes. In the emulateR it crashes all time time on the device it crashes like half the time.
I do not get a error message, but app freezes and debuuger shows it going to int main(int argc, char * argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } also apps always crashes in simulater, about half the time on iPhone.
code:
- (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: %@", result==MFMailComposeResultCancelled?@"Cancelled":
result==MFMailComposeResultSaved?@"Saved":
result==MFMailComposeResultSent?@"Sent":
result==MFMailComposeResultFailed?@"Failed":@"Unknown");
}
Upvotes: 0
Views: 235
Reputation: 41622
Put the mailctrl in an ivar - you have no strong reference to it now.
Upvotes: 1