2013-01-05 94 views
2

我已经使用下面的代码从我的iPad应用程序发送电子邮件。电子邮件编辑器打开,但是当我按下发送按钮时,什么也没有发生。有任何想法吗?发送按钮不发送

 MFMailComposeViewController *mailComposer; 
     mailComposer = [[MFMailComposeViewController alloc] init]; 
     mailComposer.mailComposeDelegate = self; 
     [mailComposer setModalPresentationStyle:UIModalPresentationFormSheet]; 
     [mailComposer setSubject:@"your custom subject"]; 
     [mailComposer setMessageBody:@"your custom body content" isHTML:NO]; 
     [self presentViewController:mailComposer animated:YES completion:nil]; 

非常感谢

+0

你什么意思是“什么都没有发生”?它不发送电子邮件或不被解雇(或者也许都是......)? – Alladinian

+0

没什么。作曲家停留在屏幕上,没有任何东西被解散。我不确定它是否实际发送,因为我不确定是否应该期望它在模拟器模式下运行时实际发送。我没有收到任何邮件。 – RGriffiths

回答

2

好吧,首先you cannot actually send emails from the simulator的,所以实际上你没有收到邮件是正常的。现在在关闭部分,这里是文档的相关部分:

您的委托对象负责在 操作完成时关闭选取器。您可以使用 dismissModalViewControllerAnimated:父视图的方法 控制器负责显示MFMailComposeViewController对象的接口。

所以唯一要做的就是实现委托方法并关闭控制器。像这样的事情也许:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    // Handle any errors here & check for controller's result as well 
    [self dismissModalViewControllerAnimated:YES]; 
} 

而且它会更容易为你刚刚提出的控制器模态在这样的(< iOS6的)第一名:

[self presentModalViewController:mailComposer animated:YES]; 

And here areMFMailComposeResult常数,你应该期望。

+0

完美 - 谢谢。自我presentModalViewController:mailComposer animated:YES];虽然是折扣iOS 6。 – RGriffiths

+0

不客气:) – Alladinian

+0

你对此绝对正确。我会解决它。 – Alladinian

1

您无法使用模拟器发送电子邮件。你应该在iPhone上试试。您还必须在iPhone中配置电子邮件帐户才能使用此功能。

您可以使用if([MFMailComposeViewController canSendMail])来检查您是否可以发送邮件。