iOS URL包含unicode的图片展示

图片URL包含unicode的内容,SDWebImage无法加载,需要unicode转utf-8编码之后,然后再去除url编码一下才可以加载.

NSString *imgUrl = [NSString stringWithFormat:@"https://xxx/pet_5776920_\U4f60\U597d.png"];

// 1. unicode utf-8编码
imgUrl = [NSString stringWithCString:[imgUrl cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSNonLossyASCIIStringEncoding];
// https://xxx/pet_5776920_你好.png

// 2. url 编码
NSString *encodedString = [imgUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
// https://xxx/pet_5776920_%E4%BD%A0%E5%A5%BD.png

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容