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并且用户没有配置邮件帐户,它将崩溃.
| 归档时间: |
|
| 查看次数: |
38040 次 |
| 最近记录: |