CFURLCreateStringByAddingPercentEscapes 替代用法
CFURLCreateStringByAddingPercentEscapes 已经被官方废弃,推荐使用 NSURLComponents 和 URLQueryItem 来代替它。
以下是一个使用 NSURLComponents 和 URLQueryItem 实现 URL 编码的示例:
NSString *stringToEncode = @"Hello, world!";
NSURLComponents *components = [[NSURLComponents alloc] init];
components.queryItems = @[[[NSURLQueryItem alloc] initWithName:@"q" value:stringToEncode]];
NSURL *url = components.URL;
这将生成一个 URL,其中查询字符串 "q=Hello%2C%20world%21" 已经被编码。
原文地址: https://www.cveoy.top/t/topic/bRWF 著作权归作者所有。请勿转载和采集!