Iphone - open URL with Japanese characters

In my application, I need to use the openURL UIApplication method to launch the browser with the following URL:

http://192.168.100.80/1003/images/test / い う yd さ dfghjk-320x160.png

Above the line is stored in NSString. When I go above the URL as a parameter in openURL, it says that the page was not found, and I noticed that the URL in the address bar is not in Japanese characters. How can I show the above url in safari?

+3
source share
1 answer

You need to avoid Japanese characters using UTF8 encoding and then replace them:

    NSString *query = @"ファイル";
    NSString *encodedQuery = [query stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    NSString *urlString = [NSString stringWithFormat:@"http://ja.wikipedia.org/wiki/%@:East_Asian_Cultural_Sphere.png", encodedQuery];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];
+2
source

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


All Articles