开发者

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]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜