2011-06-22 67 views

回答

-4

阅读Sending mail with MFMailComposeViewController

首先包括MessageUI框架工具MFMailComposeViewControllerDelegate。

#import <MessageUI/MessageUI.h> 
#import <MessageUI/MFMailComposeViewController.h> 

@interface MainViewController : UIViewController <MFMailComposeViewControllerDelegate> { 
} 

然后实现一个像这样的方法来移除邮件控制器的委托方法。

- (IBAction)pressentMailController:(id)sender { 

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"Test subject!"]; 

    // Set up the recipients. 
    /*NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", 
          nil]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", 
          @"[email protected]", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObjects:@"[email protected]", 
           nil]; 

    [picker setToRecipients:toRecipients]; 
    [picker setCcRecipients:ccRecipients]; 
    [picker setBccRecipients:bccRecipients]; 
    */ 

    // Attach an image to the email. 
    /*NSString *path = [[NSBundle mainBundle] pathForResource:@"ipodnano" 
                ofType:@"png"]; 
    NSData *myData = [NSData dataWithContentsOfFile:path]; 
    [picker addAttachmentData:myData mimeType:@"image/png" 
        fileName:@"ipodnano"]; 
    */ 
    // Fill out the email body text. 
    NSString *emailBody = @"It is raining in sunny California!"; 
    [picker setMessageBody:emailBody isHTML:NO]; 

    // Present the mail composition interface. 
    [self presentModalViewController:picker animated:YES]; 
    [picker release]; // Can safely release the controller now. 
} 

// The mail compose view controller delegate method 
- (void)mailComposeController:(MFMailComposeViewController *)controller 
      didFinishWithResult:(MFMailComposeResult)result 
         error:(NSError *)error 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 

该代码允许添加收件人,正文,主题和附件。根据需要取消注释。

enter image description here

+0

谢谢您的回答,但是,你明白我的问题不同,我的意思是:如何测试MFMailComposeViewController是否真正发送的电子邮件或不按发送键后!!?因为当我检查了我的电子邮件,我找不到从该作曲家发送的任何电子邮件(使用模拟器)我很抱歉混淆的话.. – JaHelia

+1

-1回答错误的问题。问题是如何在模拟器中测试邮件控制器。答案显示了如何编写代码,但不允许测试,因为邮件控制器在模拟器中不起作用。 – Lee

1

实际邮件发送是不可能的从模拟器。 在手机上安装应用程序以测试该应用程序。

但是你可以检验一切,你的APP可以做/控制/在模拟器中指定。在按下发送按钮后 一切都是苹果,所以你可以认为是 工作正常。

4

不,你不能测试它在模拟器...(我的意思是你的邮件将不会传递)。我们将能够测试有限的东西,如:视图将会如何,会发生什么用户点击时在取消按钮等等

测试邮件是否交付与否,你必须使用的设备。该设备应该在您的设置中配置一些邮件(例如:Gmail)。