我MFMailComposeViewController
在我的 demp 应用程序中实现。但是,由于某些原因,在我触摸以在电子邮件文本字段中添加文本后,我的应用程序崩溃了。但是在不添加任何文本的情况下发送效果很好。
我的 Xcode 没有显示太多。这是我得到的:
我已经在电子邮件文本字段中设置了初始文本。也许问题就在这里?请求任何代码,我很乐意将其包含在内。
更新:
这里有两种方法,其中第一种方法openMail
在触摸时触发UIButton
- (IBAction)openMail:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Feedback from Demo App user"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"myEMAIL@hotmail.com", @"myEMAIL2@gmail.com", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = @"Happy to hear your feedback!";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved: you saved the email message in the drafts folder.");
break;
case MFMailComposeResultSent:
NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
break;
default:
NSLog(@"Mail not sent.");
break;
}
// Remove the mail view
[self dismissModalViewControllerAnimated:YES];
}