iOS URL中含有中文处理 url出现特殊字符处理

//直接访问此url会访问失败 
//原因 掺杂中文uincode 20180813150735_\U5de5\U7a0b\U5e08\U5934\U50cf.png 
NSString *str = @"http://xxxxxx.com/uploads/image/20180813/20180813150735_\U5de5\U7a0b\U5e08\U5934\U50cf.png";
//使用stringByAddingPercentEncodingWithAllowedCharacters处理
NSString *headImgURL = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
NSLog(@"%@",headImgURL);//http://xxxxxx.com/uploads/image/20180813/20180813150735_%E5%B7%A5%E7%A8%8B%E5%B8%88%E5%A4%B4%E5%83%8F.png

参考文章
https://www.jianshu.com/p/21a21866e379
https://nshipster.cn/nscharacterset/

你可能感兴趣的:(iOS URL中含有中文处理 url出现特殊字符处理)