发送电子邮件而不打开默认邮件应用

时间:2016-05-07 05:48:09

标签: ios objective-c iphone

我想直接从我的应用程序发送邮件到电子邮件地址,而无需在我的设备上打开默认邮件应用程序。这可以做到,即使这可能是一个好主意吗? Apple允许这样做吗?我在亚马逊的应用程序中看到了这一点,邮件直接从应用程序发送。我的客户希望我也这样做。请建议我如何做到这一点。 谢谢。

1 个答案:

答案 0 :(得分:1)

尝试 MFMailComposerViewController ,这是Apple提供的默认功能。

请尝试以下代码:

MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc]init];

if ([MFMailComposeViewController canSendMail]) {

    mailComposer.mailComposeDelegate = self;

    //[mailComposer.navigationBar setBarTintColor:APPTHEME_COLOR];

    //[mailComposer.navigationBar setTintColor:[UIColor blackColor]];

    [mailComposer.navigationBar setTitleTextAttributes:
     @{NSForegroundColorAttributeName:[UIColor blackColor]}];

    [mailComposer setToRecipients:[NSArray arrayWithObjects:@"support@trackidon.com", nil]];

    [mailComposer setSubject:[NSString stringWithFormat:@"Report from %@",[USERDEFAULTS objectForKey:USERNAME]]];

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

}

这将显示一个用于发送电子邮件的视图控制器。您可以编辑内容的地址,主题和正文。

这不会让你退出应用程序。这将发生在应用程序本身内。

希望有所帮助......

相关问题