关闭邮件ComposeController

发布于 2024-12-13 09:42:44 字数 1300 浏览 0 评论 0原文

如果用户发送或取消,我会在完成后尝试从我的应用程序中忽略邮件。 但出于某种原因,这永远不会被忽视。我几乎尝试了一切。 我也记录了这个,所以我会看看它是否进入了解雇方法。问题就在那里,因为它永远不会进入解雇方法。

我做错了什么???

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽容 2024-12-20 09:42:44

您可以将此行: 替换

[self dismissModalViewControllerAnimated:YES];

为以下行:

[controller dismissModalViewControllerAnimated:YES];

you could replace this line:

[self dismissModalViewControllerAnimated:YES];

with the following line:

[controller dismissModalViewControllerAnimated:YES];
乖乖 2024-12-20 09:42:44

MFMailComposeViewController 类继承自 UINavigationController ,因此它的委托属性是该类的导航控制器“部分”的“委托”。要处理特定的邮件编辑器委托方法,您需要将对象设置为 mailComposeDelegate 属性:

mailComposer.mailComposeDelegate = self;

MFMailComposeViewController class inherits from UINavigationController 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 as mailComposeDelegate property:

mailComposer.mailComposeDelegate = self;
晨曦慕雪 2024-12-20 09:42:44

SWIFT 5.0:

如果您实现 MFMailComposeViewControllerDelegate 协议,则只需在 ViewController 中包含以下函数:

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) 
{
   controller.dismiss(animated: true, completion: nil)
}

该函数会为您处理所有事情。如果用户发送电子邮件,视图将自动消失。
任何进一步的信息:
mailComposeController

SWIFT 5.0:

If you implement the MFMailComposeViewControllerDelegate protocol, you only have to contain the following function in ViewController:

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) 
{
   controller.dismiss(animated: true, completion: nil)
}

This function handles everything for you. If the user sends the email the view disappears automatically.
Any further information:
mailComposeController

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文