iOS - 如果addAttachmentData,MFMailComposerViewController无法取消:

时间:2016-05-13 19:11:59

标签: ios objective-c mfmailcomposeviewcontroller

我的MFMailComposer代码:

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
[mailViewController setDelegate:self];
[mailViewController setSubject:@"subject"];
[mailViewController setToRecipients:[NSArray arrayWithObject:@"email@email.com"]];
[mailViewController setMessageBody:@"body" isHTML:NO];

for (int i = 0; i < self.imagesData.count; i++)
{
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd-HH-mm-ss-SSSS"];
    [mailViewController addAttachmentData:[self.imagesData objectAtIndex:i] mimeType:[self contentTypeForImageData:[self.imagesData objectAtIndex:i]] fileName:[NSString stringWithFormat:@"portfolio_%@_%d", [dateFormatter stringFromDate:[NSDate date]], i]];
}

[self presentViewController:mailViewController animated:YES completion:nil];

使用此代码我会按取消并删除草稿,没有任何反应,MFMailComposerViewController不会关闭。

我已经添加了代表:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
if(error) NSLog(@"ERROR - mailComposeController: %@", [error localizedDescription]);

if (result == MFMailComposeResultSent)
{
    NSLog(@"It's away!");
}

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[self dismissViewControllerAnimated:YES completion:nil];}

我错过了什么?

1 个答案:

答案 0 :(得分:0)

好的,我找到了答案。我很蠢。

我使用setDelegate代替setMailComposeDelegate