为什么不在应用内打开电子邮件编辑器?
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
[mailController setSubject:@"my subject"];
[mailController setMessageBody:@"my message" isHTML:NO];
mailController.mailComposeDelegate = self;
UINavigationController *myNavController = [myViewController navigationController];
if ( mailController != nil ) {
if ([MFMailComposeViewController canSendMail]){
[myNavController presentModalViewController:mailController animated:YES];
}
}
[mailController release];
Run Code Online (Sandbox Code Playgroud)
请参阅MFMailComposeViewControllerApple的文档.你可以像这样使用它:
MFMailComposeViewController *controller=[[MFMailComposeViewController alloc]init];
controller.delegate = self;
[controller setMessageBody:<#yourBody#> isHTML:<#isHTML#>];
[self presentModalViewController:controller animated:YES];
[controller release];
Run Code Online (Sandbox Code Playgroud)
不要忘记添加#import <MessageUI/MessageUI.h>您的.h文件.它将调用您委托中的方法,以便在取消或发送电子邮件(成功与否)时通知您.如果这对您有用,请告诉我.
NSString *body = @"Hello Mail";
NSString *mailtoURLString = [NSString stringWithFormat:@"mailto:?body=%@", [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailtoURLString]];
Run Code Online (Sandbox Code Playgroud)
或者,正如Mihai建议的那样,看看MFMailComposeViewController哪个允许您在不离开应用程序的情况下发送邮件.