Problem with URLWithString: when string contains Arab chars [duplicate]
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];
精彩评论