开发者

Problem with URLWithString: when string contains Arab chars [duplicate]

开发者 https://www.devze.com 2023-02-22 03:02 出处:网络
This question already has answers here: NSURL URLWithString: is null with non-english accented characters
This question already has answers here: NSURL URLWithString: is null with non-english accented characters (5 answers) Closed 8 years ago.

I have problem with my code when p开发者_JAVA百科ath contains Arab chars. In this case URLWithString always returns nil.

NSString *path = self.currentlySelectedBlogItem.linkUrl;
NSURL *url = [NSURL URLWithString:path];
[[UIApplication sharedApplication] openURL:url];

Any sugestions?


You have to Use UTF8 encoding for special characters:

NSString *path = self.currentlySelectedBlogItem.linkUrl;

NSString *encodedPath = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:encodedPath];

[[UIApplication sharedApplication] openURL:url];
0

精彩评论

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