经验分享 · 2023年4月10日

iOS 解决”‘stringByAddingPercentEscapesUsingEncoding:’ is deprecated: first deprecated in iOS 9.0 – Use -stringByAddingPercentEncodingWithAllowedCharacters: instead…”

提示

‘stringByAddingPercentEscapesUsingEncoding:’ is deprecated: first deprecated in iOS 9.0 – Use -stringByAddingPercentEncodingWithAllowedCharacters: instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid.

stringByAddingPercentEscapesUsingEncoding,这个方法是用来进行转码的,即将汉字转码。

可在iOS9.0中,该方法已经被另一个方法替代了,此方法即:

stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]。

这次在对汉字进行转码的时候就使用该方法即可。