xcode 如何在模拟器中测试 MFMailComposeViewController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6439932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to test MFMailComposeViewController in simulator
提问by JaHelia
Is there a way to test sending emails from MFMailComposeViewController
in iphone simulator ?
有没有办法测试从MFMailComposeViewController
iphone 模拟器发送电子邮件?
回答by Durga Vundavalli
No you can't test it on simulator...(I mean your mail won't be delivered).we will be able to test limited things like: how the view will be,what happens when the user clicks on cancel button etc...
不,你不能在模拟器上测试它......(我的意思是你的邮件不会被传递)。我们将能够测试有限的东西,比如:视图如何,当用户点击取消按钮时会发生什么等...
To test whether, the mail was delivered or not, you have to use a Device. The device should be configured with some mail(ex:gmail) in your settings.
要测试邮件是否已送达,您必须使用设备。该设备应在您的设置中配置一些邮件(例如:gmail)。
回答by Vincent
Actual mail sending is not possible from the simulator. Install the APP on a phone to test that.
模拟器无法实际发送邮件。在手机上安装APP进行测试。
However you can test everything that your APP can do/control/specify in the simulator. Everything after the pressing of the Send button is Apple, so you can assume that is working okay.
但是,您可以在模拟器中测试您的 APP 可以执行/控制/指定的所有内容。按下“发送”按钮后的所有内容都是 Apple,因此您可以假设它工作正常。
回答by Soner G?nül
Read Sending mail with MFMailComposeViewController
读 Sending mail with MFMailComposeViewController
First include MessageUI framework an implement MFMailComposeViewControllerDelegate.
首先包括 MessageUI 框架一个实现 MFMailComposeViewControllerDelegate。
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface MainViewController : UIViewController <MFMailComposeViewControllerDelegate> {
}
then implement a method like this one an the delegate method for removing the mail controller.
然后实现一个像这样的方法,一个删除邮件控制器的委托方法。
- (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];
}
The code allows to add recipients, body, subject and attachements. Uncomment the lines as needed.
该代码允许添加收件人、正文、主题和附件。根据需要取消注释这些行。