如何通过iOS模拟器发送电子邮件?

neh*_*hal 30 email iphone message sendmessage

我想知道是否可以通过iPhone模拟器发送电子邮件.我看过通过iphone发送电子邮件的教程如下:

http://www.edumobile.org/iphone/iphone-programming-tutorials/compose-mail-application-in-iphone/

现在要测试它是否有必要拥有真正的设备?如果我想通过iPhone模拟器发送电子邮件的方式是什么?

Fel*_*lix 32

你必须依赖于iOS的MFMailComposeResult回传mailComposeController:didFinishWithResult:error:是正确的.模拟器伪造了这个结果; 虽然它说没有发送实际邮件MFMailComposeResultSent.

提到的教程错过了一个重要的观点:在使用之前你应该做的第一件事MFMailComposeViewController是检查[MFMailComposeViewController canSendMail].NO如果用户未在其设备上配置邮件,则会返回.如果您必须支持3.0之前的iOS版本,正确的方法是检查该类是否MFMailComposeViewController存在:

Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
    if ([mailClass canSendMail])
    {
        [self displayComposerSheet];
    }
    else
    {
        [self launchMailAppOnDevice];
    }
}
else
{
    [self launchMailAppOnDevice];
}
Run Code Online (Sandbox Code Playgroud)

canSendMail-issue只能在真实设备上测试.如果您不检查canSendMail并且用户没有配置邮件帐户,它将崩溃.


Nev*_*ess 7

根据苹果论坛上讨论,要测试我们真正需要设备的功能,模拟器不支持此功能。

部分讨论:

strakesh Chicago Re: IOS 模拟器

MAIL APP 2012 年 3 月 26 日上午 7:09(响应 davemac75)

邮件应用程序在模拟器上不可用。您需要在设备上测试您的应用程序以测试该部分。