简体   繁体   English

从我的应用程序打开电子邮件

[英]Open email from my application

I am creating a game with Cocos and Sprite Builder in Objective-C, and I'm finishing the support scene but I have a problem. 我正在用Objective-C中的Cocos和Sprite Builder创建游戏,并且正在完成支持场景,但是我遇到了问题。 I want to add a button that when clicked, it opens directly the email with my address so that the users can contact me if there is some problems. 我想添加一个按钮,单击该按钮后,它将直接打开带有我的地址的电子邮件,以便用户在遇到问题时可以与我联系。

What code do I need to write to accomplish this? 为此,我需要编写什么代码?

Add the MessageUI framework and then : 添加MessageUI框架,然后:

- (void)showMailSender
{
    if (![MFMailComposeViewController canSendMail]) {
        NSLog(@"MFMailComposeViewController can't send emails.");
        return;
    } else {
        MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
        mailComposeViewController.mailComposeDelegate = self;
        [mailComposeViewController setSubject:@"Subject"];
        [mailComposeViewController setToRecipients:@[@"example@domain.com"]];
        [self presentViewController:mailComposeViewController animated:YES completion:nil];
    }
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    [controller.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM