如何通过iOS模拟器发送电子邮件?
我想知道是否可以通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须依赖 iOS 来确保
mailComposeController:didFinishWithResult:error:
中返回的MFMailComposeResult
是否正确。模拟器会伪造这个结果;虽然显示为MFMailComposeResultSent
,但并未发送实际邮件。提到的教程忽略了一个重要点:在使用
MFMailComposeViewController
之前,您应该做的第一件事是检查[MFMailComposeViewController canSendMail]
。如果用户尚未在其设备上配置邮件,则将返回NO
。如果您必须支持 3.0 之前的 iOS 版本,正确的方法是检查 MFMailComposeViewController 类是否存在:但 canSendMail 问题只能在真实设备上进行测试。如果不检查 canSendMail 并且用户没有配置邮件帐户,它将崩溃。
You have to rely on the iOS that the
MFMailComposeResult
that is handed back inmailComposeController:didFinishWithResult:error:
is correct. The simulator fakes that result; no actual mail is sent although it saysMFMailComposeResultSent
.The tutorial mentioned misses an important point: The first thing you should do before using
MFMailComposeViewController
is to check[MFMailComposeViewController canSendMail]
. That will returnNO
, 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 classMFMailComposeViewController
exists: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.
根据苹果论坛上的讨论,要测试我们真正需要设备的功能,模拟器不需要支持此功能。
讨论的一部分:
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:
是的,如果您想实际发送电子邮件,这是必要的。
在大多数情况下,您无需担心,因为邮件将由苹果应用程序发送,因此您只需验证您的应用程序是否正在响应并启动邮件编辑器。我认为唯一有问题的是您是否想确保附件和图像正确发送。在这种情况下,您可以将测试版发送给拥有 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.
您可以使用模拟器上的 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.