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

发布于 2024-10-22 09:35:20 字数 347 浏览 4 评论 0原文

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

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

现在测试是否需要有真实设备?如果我想发送电子邮件,该怎么办 通过iPhone模拟器?

I want to know if it's possible to send email through iPhone simulator. I have seen the
tutorial for sending an email through iphone as below:

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

Now to test it is it necessary to have real device? What is the way if I want to send email
through iPhone simulator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

半葬歌 2024-10-29 09:35:20

您必须依赖 iOS 来确保 mailComposeController:didFinishWithResult:error: 中返回的 MFMailComposeResult 是否正确。模拟器会伪造这个结果;虽然显示为 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];
}

但 canSendMail 问题只能在真实设备上进行测试。如果不检查 canSendMail 并且用户没有配置邮件帐户,它将崩溃。

You have to rely on the iOS that the MFMailComposeResult that is handed back in mailComposeController:didFinishWithResult:error: is correct. The simulator fakes that result; no actual mail is sent although it says MFMailComposeResultSent.

The tutorial mentioned misses an important point: The first thing you should do before using MFMailComposeViewController is to check [MFMailComposeViewController canSendMail]. That will return NO, if the user hasn't configured mail on their device. If you must support an iOS version prior to 3.0 the correct way is to check if the class MFMailComposeViewController exists:

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

The canSendMail-issue can only be tested on a real device though. It will crash if you don't check canSendMail and the user has no mail account configured.

烛影斜 2024-10-29 09:35:20

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

讨论的一部分:

星光
芝加哥回复:IOS 模拟器

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

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

As per the discussion on apple forum, to test the functionality we really need a device, simulator does not support this functionality.

A part from discussion:

sptrakesh
Chicago Re: IOS SIMULATOR

MAIL APP Mar 26, 2012 7:09 AM (in response to davemac75)

The mail application is not available on the simulator. You will need
to test your application on a device to test that part.

无可置疑 2024-10-29 09:35:20

是的,如果您想实际发送电子邮件,这是必要的。

在大多数情况下,您无需担心,因为邮件将由苹果应用程序发送,因此您只需验证您的应用程序是否正在响应并启动邮件编辑器。我认为唯一有问题的是您是否想确保附件和图像正确发送。在这种情况下,您可以将测试版发送给拥有 iPhone 的人,并请他为您检查。

重要
拥有设备对于开发来说至关重要,您的模拟器的行为与设备并不完全相同。他是一个宽恕者,根据我的经验,我总是遇到与模拟器无关的设备问题。

Yes it is necessary if you want to actually send the email.

in most of the cases there is no need for you to worry as the mail is going to be sent by apple app, so you will need only to verify that your app is responding and launches the mail composer. The only thing i can think as problematic is if you want to make sure that attachments and images are sent properly. In this case you can send a beta to someone with iphone and ask him to check it for you.

important
having a device is critic to developing, your simulator does not behave exactly as the device. he is a forgiver and in my experience i always had issues with the device that weren't with the simulator.

青衫负雪 2024-10-29 09:35:20

您可以使用模拟器上的 MessageUI 框架来撰写和“发送”消息,但我不相信有一种方法可以实际发送消息。但是,一旦用户点击消息撰写视图中的“发送”按钮,您的代码在发送消息方面就不再发挥任何作用。因此模拟器的功能足以让您开发和测试您的应用程序。

至于是否有必要拥有一台真实的设备,我想说的是,无论如何,在某些时候你都需要在一台或多台设备上进行测试。模拟器是一个很棒的工具,但在一定程度上它无法替代在真实设备上运行应用程序。

You can use the MessageUI framework on the simulator to compose and 'send' messages, but I don't believe there's a way to actually send the message. Once the user hits the Send button in the message composition view, though, your code doesn't have any role in sending the message. So the simulator does enough that you can develop and test your app.

As for whether it's necessary to have a real device, I'd say that at some point you need to test on one or more devices no matter what. The simulator is a great tool, but after a certain point it's no substitute for running your app on the real thing.

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