美文网首页
iOS url中文转码

iOS url中文转码

作者: 诠释残缺 | 来源:发表于2017-05-17 11:23 被阅读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

相关文章

网友评论

      本文标题:iOS url中文转码

      本文链接:https://www.haomeiwen.com/subject/oocdxxtx.html