crash 保护 review by hongmo
Showing
1 changed file
with
18 additions
and
10 deletions
@@ -52,8 +52,15 @@ | @@ -52,8 +52,15 @@ | ||
52 | completed:(SDWebImageCompletionWithFinishedBlock)completedBlock | 52 | completed:(SDWebImageCompletionWithFinishedBlock)completedBlock |
53 | { | 53 | { |
54 | @try { | 54 | @try { |
55 | - if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].isImagePerformanceTrackEnable){ | ||
56 | - [[YH_EventCollector sharedInstance] timeEventStartWithWebImageDownloadURL:url.absoluteString]; | 55 | + if ([url isKindOfClass:NSString.class]) { |
56 | + url = [NSURL URLWithString:(NSString *)url]; | ||
57 | + } | ||
58 | + | ||
59 | + // Prevents app crashing on argument type error like sending NSNull instead of NSURL | ||
60 | + if ([url isKindOfClass:NSURL.class]) { | ||
61 | + if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].isImagePerformanceTrackEnable){ | ||
62 | + [[YH_EventCollector sharedInstance] timeEventStartWithWebImageDownloadURL:url.absoluteString]; | ||
63 | + } | ||
57 | } | 64 | } |
58 | } @catch (NSException *exception) { | 65 | } @catch (NSException *exception) { |
59 | YHLog(@"%@ error: %@", self, exception); | 66 | YHLog(@"%@ error: %@", self, exception); |
@@ -62,14 +69,15 @@ | @@ -62,14 +69,15 @@ | ||
62 | return [self yher_downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { | 69 | return [self yher_downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { |
63 | 70 | ||
64 | @try { | 71 | @try { |
65 | - | ||
66 | - if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].isImagePerformanceTrackEnable){ | ||
67 | - if (cacheType == SDImageCacheTypeNone) {//暂时只去下载的图片的时间,过滤掉读缓存的时间 | ||
68 | - if (error) { | ||
69 | - [[YH_EventCollector sharedInstance] timeEventEndWithWebImageDownloadURL:url.absoluteString status:YHEventLoadStatusFailed]; | ||
70 | - }else{ | ||
71 | - [[YH_EventCollector sharedInstance] timeEventEndWithWebImageDownloadURL:url.absoluteString status:YHEventLoadStatusSuc]; | ||
72 | - } | 72 | + if ([url isKindOfClass:NSURL.class]) { |
73 | + if ([YHEventReport sharedInstance].isPerformanceTrackEnabled && [YHEventReport sharedInstance].isImagePerformanceTrackEnable){ | ||
74 | + if (cacheType == SDImageCacheTypeNone) {//暂时只去下载的图片的时间,过滤掉读缓存的时间 | ||
75 | + if (error) { | ||
76 | + [[YH_EventCollector sharedInstance] timeEventEndWithWebImageDownloadURL:url.absoluteString status:YHEventLoadStatusFailed]; | ||
77 | + }else{ | ||
78 | + [[YH_EventCollector sharedInstance] timeEventEndWithWebImageDownloadURL:url.absoluteString status:YHEventLoadStatusSuc]; | ||
79 | + } | ||
80 | + } | ||
73 | } | 81 | } |
74 | } | 82 | } |
75 | } @catch (NSException *exception) { | 83 | } @catch (NSException *exception) { |
-
Please register or login to post a comment