关闭邮件ComposeController
如果用户发送或取消,我会在完成后尝试从我的应用程序中忽略邮件。 但出于某种原因,这永远不会被忽视。我几乎尝试了一切。 我也记录了这个,所以我会看看它是否进入了解雇方法。问题就在那里,因为它永远不会进入解雇方法。
我做错了什么???
- (IBAction)sendmail:(id)sender{
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(image, 1.0);
if ( [MFMailComposeViewController canSendMail] ) {
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.delegate = self;
[mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];
[mailComposer setSubject:@"Hello from My App!"];
NSString *emailBody = @"Sent from My App, Still not in AppStore!";
[mailComposer setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:mailComposer animated:YES];
}
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
NSLog (@"mail finished"); // NEVER REACHES THIS POINT.
}
I am trying to dismiss the mail from my app after it's done if user sends or cancels.
But for some reasone this never dismisses. I tried almost everything.
I have also logged this so I will see if it went to dissmiss method. And the problem is there since it never enters the dismiss method.
What am i doing wrong???
- (IBAction)sendmail:(id)sender{
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation(image, 1.0);
if ( [MFMailComposeViewController canSendMail] ) {
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.delegate = self;
[mailComposer addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"attachment.jpg"];
[mailComposer setSubject:@"Hello from My App!"];
NSString *emailBody = @"Sent from My App, Still not in AppStore!";
[mailComposer setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:mailComposer animated:YES];
}
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
NSLog (@"mail finished"); // NEVER REACHES THIS POINT.
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将此行: 替换
为以下行:
you could replace this line:
with the following line:
MFMailComposeViewController 类继承自 UINavigationController ,因此它的委托属性是该类的导航控制器“部分”的“委托”。要处理特定的邮件编辑器委托方法,您需要将对象设置为
mailComposeDelegate
属性:MFMailComposeViewController
class inherits fromUINavigationController
and so its delegate property is 'delegate' for navigation controller 'part' of the class. To handle specific mail composer delegate methods you need to set your object asmailComposeDelegate
property:SWIFT 5.0:
如果您实现 MFMailComposeViewControllerDelegate 协议,则只需在 ViewController 中包含以下函数:
该函数会为您处理所有事情。如果用户发送电子邮件,视图将自动消失。
任何进一步的信息:
mailComposeController
SWIFT 5.0:
If you implement the MFMailComposeViewControllerDelegate protocol, you only have to contain the following function in ViewController:
This function handles everything for you. If the user sends the email the view disappears automatically.
Any further information:
mailComposeController