当路径包含阿拉伯字符时,我的代码有问题。在这种情况下,URLWithString始终返回nil。
NSString *path = self.currentlySelectedBlogItem.linkUrl;
NSURL *url = [NSURL URLWithString:path];
[[UIApplication sharedApplication] openURL:url];
任何sugestions?
答案 0 :(得分:2)
您必须对特殊字符使用UTF8编码:
NSString *path = self.currentlySelectedBlogItem.linkUrl;
NSString *encodedPath = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:encodedPath];
[[UIApplication sharedApplication] openURL:url];