当操作表上的按钮被调用时,我有下面的代码被调用。但当我按取消,然后删除草案,它只是冻结,不解散。我在app的其他地方使用相同的代码它从tableview单元格的select中调用它在那里工作。知道为什么这里不行吗?
当它冻结时,控制台也没有错误消息。
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Dr. Chrono Support"];
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSString* versionNum = [infoDict objectForKey:@"CFBundleVersion"];
NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
NSString *text = [NSString stringWithFormat:@"%@ %@",appName,versionNum];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"contact@drchrono.com"];
//NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
//NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];
[picker setToRecipients:toRecipients];
//[picker setCcRecipients:ccRecipients];
//[picker setBccRecipients:bccRecipients];
// Attach an image to the email
//NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
//NSData *myData = [NSData dataWithContentsOfFile:path];
//[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];
// Fill out the email body text
NSString *emailBody = text;
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
您需要实现委托方法:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
然后在这个委托方法中添加:
[self dismissModalViewControllerAnimated:YES];
,它应该工作正常。
你不需要寻找结果(只有当你想要显示"谢谢"警报或其他东西,例如,如果用户确实点击了发送)
使用以下代码
- (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 the next time the user connects to email");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error");
break;
default:
NSLog(@"Mail not sent");
break;
}
[self dismissModalViewControllerAnimated:YES];
}