简体   繁体   中英

iphone - open URL with japanese characters

In my application, the requirement is to use UIApplication's openURL method to start browser with following URL:

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

Above string is stored in NSString. When I am passing above URL as parameter to openURL, its saying that the page is not found and I noticed that the URL in the address bar is not in japanese characters. How can I show above URL in safari?

You have to escape 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]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM