使用openURL发送邮件的问题 [英] Issue with mail sending using openURL
本文介绍了使用openURL发送邮件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用openURL打开邮件客户端面临的一个问题。这是代码。
I'm facing a issue with opening mail client using openURL. Here is the code.
NSString *subject = @"Demo Subject";
NSString *body = @"<html><head>Header</head><body><a href=\"http://example.com\">Here is the demo link</a></body></html>";
NSString *urlString = [NSString stringWithFormat:@"mailto:?&subject=%@&body=%@",subject,body];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
我想,是否需要使用特殊字符的任何类型的编码,这是提供,但是
I guess, is there any kind of encoding needed to use special characters, which is do present, but not shown here in the sample text.
谢谢
推荐答案
NSString *htmlBody = @"you probably want something HTML-y here";
// First escape the body using a CF call
NSString *escapedBody = [(NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)htmlBody, NULL, CFSTR("?=&+"), kCFStringEncodingUTF8) autorelease];
// Then escape the prefix using the NSString method
NSString *mailtoPrefix = [@"mailto:?subject=Some Subject&body=" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// Finally, combine to create the fully escaped URL string
NSString *mailtoStr = [mailtoPrefix stringByAppendingString:escapedBody];
// And let the application open the merged URL
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailtoStr]];
这篇关于使用openURL发送邮件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文