我想在电子邮件应用中点击一下URL.问题是参数化的URL会因为URL中的"&"而破坏它.下面的body变量是问题行.两种版本的"身体"都是不正确的.电子邮件应用程序打开后,文本将停在"... link:"处.对&符号进行编码需要什么?
NSString *subject = @"This is a test"; NSString *encodedSubject = [subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //NSString *body = @"This is a link: click me"; //original NSString *body = @"This is a link: click me"; //have also tried & NSString *encodedBody = [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *formattedURL = [NSString stringWithFormat: @"mailto:myname@somedomain.com?subject=%@&body=%@", encodedSubject, encodedBody]; NSURL *url = [[NSURL alloc] initWithString:formattedURL]; [[UIApplication sharedApplication] openURL:url];
Konstantinos.. 20
对于URL编码标准中的HEX,&符号为%26
对于URL编码标准中的HEX,&符号为%26
我一直在使用-[NSString gtm_stringByEscapingForURLArgument]
,它在Google Toolbox for Mac中提供,特别是在GTMNSString + URLArguments.h和GTMNSString + URLArguments.m中.