iOS url中文转码

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中文转码)