iOS url中文转码

2017-05-17  本文已影响27人  诠释残缺
NSString *urlStr = @"www.baidu.com/百度";

iOS9之前

urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

iOS9之后

urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];

打印结果
www.baidu.com/%E7%99%BE%E5%BA%A6
www.baidu.com/%E7%99%BE%E5%BA%A6

上一篇 下一篇

猜你喜欢

热点阅读