Removing special characters (ø, æ) for use inside a URL

I am trying to display an image with a URL source in an iOS application, but it does not display.

The image URL is an example of an example.

When escaping this line using the following Objective-C code:

NSString *url= [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)originalpath, NULL, CFSTR("øæ"), kCFStringEncodingUTF8) autorelease]; 

result (encoded by øæ): live xml path

All of my files that store urls use text encoding (UTF-8).

How can I avoid the correct url so that the image is displayed?

+4
source share
3 answers

don't go for ascii encoding try

 NSString *URLString = [yourImagepath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL URLWithString:URLString]; 

I hope this helps you.

+12
source

I believe that you need to avoid your url string before using it as a url ...

 NSString *URLString = [yourImagepath stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; NSURL *url = [NSURL URLWithString:URLString]; 
0
source

There was the same issue with iOS with German umlauts. Category NSURL NSURL + IFUnicodeURL solved the problem for me, do not be alarmed by the amount of C code there, hidden :)

0
source

Source: https://habr.com/ru/post/1381633/


All Articles