我正在使用MFMailComposeVC,想拥有如果用户取消,显示alertView并尝试让他/她再次发送电子邮件的功能。
因此,如果结果状态未发送,则在MFMailComposeViewControllerDelegate中,我不会解散VC。
然后有趣的是:用户取消,显示alertView,MFVC不会被解雇,然后再次发送,委托方法不会被触发。实际上无论用户做什么(发送,取消,保存草稿),委托方法只会触发一次。
代码示例:
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if (result == MFMailComposeResultSent){
[controller dismissViewControllerAnimated:YES completion:NULL];
} else {
NSLog(@"do something like show alert");
}
}
委托方法只会触发一次
编辑:目前的mailVC代码:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
[controller setToRecipients:@"to email"];
[controller setSubject:@"the subject"];
[controller setMessageBody:@"the message body" isHTML:NO];
controller.mailComposeDelegate = self;
controller.modalPresentationStyle = UIModalPresentationFormSheet;
if (controller) {
[self presentViewController:controller animated:YES completion:nil];
}
答案 0 :(得分:0)
您之前的代码存在一个大问题。您只有在成功发送邮件但使用取消操作对其进行测试时才会解雇它。
将此代码用于MFMailComposeViewControllerDelegate:
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if (result == MFMailComposeResultSent){
// Removed dismiss code from here
} else {
NSLog(@"do something like show alert");
}
[controller dismissViewControllerAnimated:YES completion:NULL];
}