Function to detect the NSStringEncoding from NSURLResponse?

只谈情不闲聊 提交于 2019-12-01 11:31:24

There is a better way.

You can get the encoding name from URLResponse as a string, then search for the appropriate NSStringEncoding.

NSString *encodingName = [aURLResponse textEncodingName];
NSStringEncoding encodingType = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)encodingName));

Also encodingName might be nil and if there is no appropriate result for the provided encodingName the result value for the encodingType variable will not be valid.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!