Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS 5从应用程序发送电子邮件的最简单方式_Iphone_Ios_Email_Nsstring - Fatal编程技术网

Iphone iOS 5从应用程序发送电子邮件的最简单方式

Iphone iOS 5从应用程序发送电子邮件的最简单方式,iphone,ios,email,nsstring,Iphone,Ios,Email,Nsstring,我刚刚尝试使用此代码发送电子邮件,但似乎有效: NSString* urlEmail = [NSString stringWithString: @"mailto:foo@example.com?cc=bar@example.com&subject=test%20from%20me!&body=this%20is%20a%20test!"]; [[UIApplication sharedApplication] openURL: [NSURL URLWithString: ur

我刚刚尝试使用此代码发送电子邮件,但似乎有效:

NSString* urlEmail = [NSString stringWithString: @"mailto:foo@example.com?cc=bar@example.com&subject=test%20from%20me!&body=this%20is%20a%20test!"];

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlEmail]];
唯一的问题是,有没有一个函数可以用来自动转义普通NSString中的所有内容,这样我就不必像这样手动写出它了?如果不是,如何使用stringWithFormat而不与字符串中已有的%符号冲突?我基本上希望能够动态地附加到、主题、主体等。

根据,您可以这样转义:

NSString *urlStr = [urlEmail stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
根据,你可以这样逃跑:

NSString *urlStr = [urlEmail stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

使用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];

使用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];

此外,此答案(同一问题)显示了对其他字符的处理:此外,此答案(同一问题)显示了对其他字符的处理:此方法确实更可靠。我需要添加什么才能访问MFMailComposeViewController?iOS 5不支持MessageUI.framewor。如果有其他方法,该怎么做?此方法确实更可靠。我需要添加什么才能访问MFMailComposeViewController?iOS 5不支持MessageUI.framewor。如果有其他方法,怎么做?