0

这是我的代码

CFStringRef escapedStr;

  escapedStr = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                       originalString,
                                                       leaveUnescaped,
                                                       kCharsToForceEscape,
                                                       kCFStringEncodingUTF8);

错误是:

CFURLCreateStringByAddingPercentEscapes 在 ios 9.0 中已弃用,请使用 stringByAddingPercentEncodingWithAllowedCharacters,它始终使用推荐的 UTF-8 设置。

有人可以帮助如何在上面的代码中CFURLCreateStringByAddingPercentEscapes替换。stringByAddingPercentEncodingWithAllowedCharacters

4

1 回答 1

-1

使用下面的代码可能会有所帮助

CFStringRef escapedStr;
escapedStr = (__bridge CFStringRef)([str stringByAddingPercentEncodingWithAllowedCharacters:[kCFAllocatorDefault,originalString,leaveUnescaped,kCharsToForceEscape,kCFStringEncodingUTF8]]);// here str is your NSString
于 2016-05-28T08:05:18.553 回答