开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜