2016-05-13 57 views
0

我MFMailComposer代码:的iOS - MFMailComposerViewController无法取消的话addAttachmentData:

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; 
[mailViewController setDelegate:self]; 
[mailViewController setSubject:@"subject"]; 
[mailViewController setToRecipients:[NSArray arrayWithObject:@"[email protected]"]]; 
[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];} 

我缺少什么?

+0

如果删除附件,是否工作正常? – Bhanupriya

+0

代表是否被调用?有错误吗? –

回答

0

好的我找到了答案。我犯傻了。

我用setDelegate代替setMailComposeDelegate

+2

这是一个容易犯的错误,因为有两个不同的委托属性。 – rmaddy