NSURL with special characters (åäö)

末鹿安然 提交于 2019-12-06 05:26:15

I think it'll depend entirely on what encoding the web server is using.

Since ISO-Latin-1 doesn't seem, from your test, to work, you might try replacing kCFStringEncodingISOLatin1 with kCFStringEncodingUTF8.

Try this :

NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
    NULL,
    (CFStringRef)unencodedString,
    NULL,
    (CFStringRef)@"!*'();:@&=+$,/?%#[]",
    kCFStringEncodingISOLatin1 );

Unfortunately, the stringByAddingPercentEscapesUsingEncoding method doesn't encode all special characters properly.

Source: How to really URL encode an NSString in Objective-C, iPhone, etc.

EDIT:

Have you tried

NSString *urlString = [NSString stringWithFormat: @".../Images/%@Image.png", playerName]; 

NSURL *url = [NSURL URLWithString: [urlString stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding]];

Note the NSISOLatin1StringEncoding instead of NSUTF8StringEncoding

Try This

To create NSURL

 NSURL *url = [[NSURL alloc]initWithString:stringURL];

The stringURL is the string representing URL. While logging, try this

 NSLog("%@",[url absoluteString]);

I ran into this issue due to "%C3%89%C3%89" which converts to ÉÉ within a url I was attempting to load. This seemed to convert the url into the desired format to allow me to download the file from the URL.

NSURL *url = [NSURL URLWithString:[[imageURL stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!