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]];
精彩评论