发送按钮不发送

时间:2013-01-05 17:39:47

标签: ios xcode

我使用以下代码从我的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];

非常感谢

2 个答案:

答案 0 :(得分: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 are你期望的MFMailComposeResult常数。

答案 1 :(得分:1)

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

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