在我的代码中,从iOS 9开始,CFURLCreateStringByAddingPercentEscapes方法被标记为不推荐使用。我的代码如下:
static NSString *encodeByAddingPercentEscapes(NSString *input) {
NSString *encodedValue = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)input, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8));
return encodedValue;
}
该警告建议我使用[NSString stringByAddingPercentEncodingWithAllowedCharacters:]
如何使用较新的方法实现相同的结果?
发布于 2017-07-04 16:23:23
您可以使用[@"“stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet URLQueryAllowedCharacterSet]。还有很多设置为use:URLPathAllowedCharacterSet、URLQueryAllowedCharacterSet.etc的
https://stackoverflow.com/questions/44910208
复制