iphone中的邮箱编程?
我希望保存不同用户的电子邮件地址,并且我希望在单击电子邮件时打开邮箱的新邮件,与iphone中的电话簿电子邮件相同iphone中的邮箱编程?,iphone,email,Iphone,Email,我希望保存不同用户的电子邮件地址,并且我希望在单击电子邮件时打开邮箱的新邮件,与iphone中的电话簿电子邮件相同 我应该怎么做?在邮件中创建新邮件: NSString *subject = @"The subject"; NSString *body = @"The message"; NSString *address = @"mail@address.com"; NSString *cc = @"mail@address.com"; NSString *path = [NSString s
我应该怎么做?在邮件中创建新邮件:
NSString *subject = @"The subject";
NSString *body = @"The message";
NSString *address = @"mail@address.com";
NSString *cc = @"mail@address.com";
NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
您应该使用
MFMailComposeViewController
类和实现MFMailComposeViewControllerDelegate
协议
首先发送消息:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent) {
NSLog(@"It's gone!");
}
[self dismissModalViewControllerAnimated:YES];
}
发送后,您将在mailComposeController
:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent) {
NSLog(@"It's gone!");
}
[self dismissModalViewControllerAnimated:YES];
}