2012-03-15 28 views
1

我只是尝试使用此代码来发送电子邮件,它似乎工作发送电子邮件5最简单的方法:的iOS从一个应用程序

NSString* urlEmail = [NSString stringWithString: @"mailto:[email protected][email protected]&subject=test%20from%20me!&body=this%20is%20a%20test!"]; 

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlEmail]]; 

唯一的问题是,有没有我可以使用自动跳脱功能一切正常NSString中,所以我不必手动写出这样的?如果不是,我怎样才能使用stringWithFormat而不与已经在字符串中的%符号发生冲突?我基本上希望能够动态追加到主题,主体等。

回答

9

使用MFMailComposeViewController:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
picker.mailComposeDelegate = self; 
[picker setToRecipients:recipients]; 
[picker setSubject:subject]; 
[picker setMessageBody:body isHTML:YES]; 
[self presentModalViewController:picker animated:YES]; 
[picker release]; 
+0

这种方法真的更可靠 – 2012-03-15 03:09:12

+0

我需要添加什么才能访问MFMailComposeViewController? – gonzobrains 2012-03-15 15:24:42

+1

添加消息UI.framework – nebulabox 2012-03-22 03:27:04

1

https://stackoverflow.com/a/917630/535632,你可以逃脱这样的:

NSString *urlStr = [urlEmail stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
+0

另外,这个答案(同样的问题)显示的附加字符处理:HTTP://计算器。 com/a/4140183/535632 – 2012-03-15 03:04:49

相关问题