Authored by gaoqiang xu

优化url加载

@@ -45,7 +45,16 @@ @@ -45,7 +45,16 @@
45 45
46 - (void)setUrl:(NSString *)url 46 - (void)setUrl:(NSString *)url
47 { 47 {
48 - _url = url.length>0?[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]:url; 48 + // 检验url是否能正常转成NSURL,防止webview不能加载
  49 + BOOL isValidUrl = ([NSURL URLWithString:url] != nil);
  50 +
  51 + if (url.length > 0
  52 + && !isValidUrl) {
  53 + // 如果url里面含有需要转码的字符,则这里进行一次编码
  54 + _url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  55 + } else {
  56 + _url = url;
  57 + }
49 } 58 }
50 59
51 - (void)didMoveToSuperview 60 - (void)didMoveToSuperview