如何通过iOS模拟器发送电子邮件? [英] How to send an email through iOS simulator?
问题描述
我想知道是否可以通过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 /
现在要测试,是否有必要拥有真实的设备?如果我想通过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?
推荐答案
你必须依靠iOS在 mailComposeController:didFinishWithResult:error:
中传回的 MFMailComposeResult
是正确的。模拟器假冒结果;没有实际的邮件发送,虽然它说 MFMailComposeResultSent
。
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
.
提及的教程错过了一个重要的一点strong>:在使用 MFMailComposeViewController
之前,首先要检查 [MFMailComposeViewController canSendMail]
。如果用户尚未在其设备上配置邮件,则将返回 NO
。如果您必须在3.0之前支持iOS版本,则正确的方法是检查课程 MFMailComposeViewController
是否存在:
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];
}
canSendMail问题只能在真实的设备上进行测试。如果您不检查canSendMail并且用户没有配置邮件帐户,它将崩溃。
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.
这篇关于如何通过iOS模拟器发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!