2013-03-13 58 views
0

我已阅读其他线程并尝试多个变量。在应用程序电子邮件将发送电子邮件,但不会解雇在Xcode

我有一个应用程序,附加到应用程序内的电子邮件的屏幕截图。
当我按下发送或取消按钮时,电子邮件不会消失。

不知道我是否有此操作的委托。

代码:

.h

- (IBAction)openMail: (id)sender; 

.m

//Open Mail 
- (IBAction)openMail: (id)sender { 
UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
//UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 

NSData * imageData = UIImageJPEGRepresentation(viewImage,2.0); 

if ([MFMailComposeViewController canSendMail]) { 
    MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc]   
init]; 
    mailComposer.delegate = self; 
    [mailComposer addAttachmentData:imageData mimeType:@"image/png" 
fileName:@"attachment.jpng"]; 

    /* Configure other settings */ 
    [mailComposer setSubject:@""]; 
    [mailComposer setToRecipients:[NSArray arrayWithObjects:@"", nil]]; 
    [mailComposer setToRecipients:[NSArray arrayWithObjects:@"%@", nil]]; 
    [mailComposer setSubject:@"4-4-2 Tactics/Line Up"]; 
    //[mailComposer setMessageBody:AddNotesTextField.text isHTML:NO]; 
    [mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 

    [self presentViewController:mailComposer animated:YES completion:nil]; 
} 

- (void)mailComposeController:(MFMailComposeViewController*)controller 
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{ 
if (error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message: 
[NSString stringWithFormat:@"Error %@", [error description]] delegate:self 
cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; 
    [alert show]; 
} 
[self dismissViewControllerAnimated:YES completion:NULL]; 

} 

newMedia = YES; 
} 

回答

1

想通弄明白了。

这是我需要的。

//打开邮件

- (IBAction)openMail: (id)sender { 

UIGraphicsBeginImageContext(self.view.bounds.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
//UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 

NSData * imageData = UIImageJPEGRepresentation(viewImage,2.0); 


MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init]; 
[mailComposer setMailComposeDelegate:self]; 
if ([MFMailComposeViewController canSendMail]) { 
    [mailComposer setToRecipients:[NSArray arrayWithObjects:@"%@", nil]]; 
    [mailComposer setSubject:@"4-4-2 Tactics/Line Up"]; 
    [mailComposer setMessageBody:AddNotesTextField.text isHTML:NO]; 
    [mailComposer addAttachmentData:imageData mimeType:@"image/png" fileName:@"attachment.jpng"]; 
    [mailComposer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 
    [self presentViewController:mailComposer animated:YES completion:nil]; 
} 

newMedia = YES; 


} 

非常微妙的变化

+0

什么是除了订单和设置委托的不同方式的改变?我有同样的问题,但无法修复 – Tumtum 2014-06-04 19:15:06

+0

没关系,我注意到了现在的完成方法:) – Tumtum 2014-06-04 19:17:08

1

也许你应该试试这个

[self dismissViewControllerAnimated:YES completion:nil]; 
相关问题