草庐IT

CFURLCreateStringByAddingPercentE

全部标签

iphone - CFURLCreateStringByAddingPercentEscapes 返回 NULL

我对用于百分比转义非法符号的类别方法有疑问。这是我用于该任务的代码:@implementationNSString(URLEncoding)-(NSString*)urlEncodeUsingEncoding:(NSStringEncoding)encoding{NSString*s=(NSString*)CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)self,NULL,(CFStringRef)@"!*'\"();:@&=+$,/?%#[]%",CFStringConvertNSStringEncodingToEn

ios - 需要为 URL 编码 NSString。 CFURLCreateStringByAddingPercentEscapes 处理我的字符串

我的音乐播放器应用需要能够通过RESTAPI将歌曲、艺术家和专辑名称发送到Last.fm。为了正确地发布这些值,我需要对它们进行编码,以便它们是URL安全的(替换&、/、+等)我做了很多研究,但找不到适合我的答案。我在网上和StackOverflow上找到的最常见答案是:NSString*encodedString=(__bridgeNSString*)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridgeCFStringRef)stringToEncode,NULL,(CFStringRef)@"!*'();:@&=+$,/?%#

ios - Objective-C 'CFURLCreateStringByAddingPercentEscapes' 已弃用 : first deprecated in iOS 9. 0

我收到了这个警告:'CFURLCreateStringByAddingPercentEscapes'isdeprecated:firstdeprecatediniOS9.0-Use[NSStringstringByAddingPercentEncodingWithAllowedCharacters:]instead,whichalwaysusestherecommendedUTF-8encoding,andwhichencodesforaspecificURLcomponentorsubcomponent(sinceeachURLcomponentorsubcomponenthasdi

ios - CFURLCreateStringByAddingPercentEscapes 在 iOS 9 中被弃用,我如何使用 "stringByAddingPercentEncodingWithAllowedCharacters"

我有以下代码:return(NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)string,NULL,CFSTR(";:@&=+$,/?%#[]"),kCFStringEncodingUTF8);Xcode表示它在iOS9中已弃用。那么,我该如何使用stringByAddingPercentEncodingWithAllowedCharacters呢?谢谢! 最佳答案 试试这个NSString*value=@"";va