应用内电子邮件将发送电子邮件但不会在 Xcode 中关闭
Posted
技术标签:
【中文标题】应用内电子邮件将发送电子邮件但不会在 Xcode 中关闭【英文标题】:In app email will send email but won't dismiss in Xcode 【发布时间】:2013-03-13 20:36:57 【问题描述】:我已经阅读了其他线程并尝试了多个变量。
我有一个将屏幕截图附加到应用内电子邮件的应用。 当我按下发送或取消按钮时,电子邮件不会关闭。
不确定我是否有此操作的代表。
代码:
.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;
非常微妙的变化
【讨论】:
除了顺序和设置委托的方式不同外,还有什么变化?我有同样的问题,但无法解决【参考方案2】:也许你应该试试这个
[self dismissViewControllerAnimated:YES completion:nil];
【讨论】:
以上是关于应用内电子邮件将发送电子邮件但不会在 Xcode 中关闭的主要内容,如果未能解决你的问题,请参考以下文章
MFMailComposeViewController 视图不会第二次关闭