SDWebImage加载同一个链接地址的不同图像异常的解决方案

2023-05-30  本文已影响0人  海文_L
SDWebImageDownloaderRequestModifier *requestModifier = [SDWebImageDownloaderRequestModifier requestModifierWithBlock:^NSURLRequest * _Nullable(NSURLRequest * _Nonnull request) {

        NSFileManager *fm = [[NSFileManager alloc] init];

        NSString *imgKey = [SDWebImageManager.sharedManager cacheKeyForURL:request.URL];

        NSString *imgPath = [SDImageCache.sharedImageCache cachePathForKey:imgKey];

        NSDictionary*fileAttr = [fmattributesOfItemAtPath:imgPatherror:nil];

        if(fileAttr !=nil) {

            NSDate*fileModDate = [fileAttrobjectForKey:NSFileModificationDate];

            NSDateFormatter*dateFormatter = [[NSDateFormatteralloc]init];

            [dateFormattersetDateFormat:@"EEE, dd MMM yyyy HH:mmiss z"];

            NSString*lastModifiedStr = [dateFormatterstringFromDate:fileModDate];

            lastModifiedStr = lastModifiedStr.length>0? lastModifiedStr :@"";

            NSMutableURLRequest*mutableRequest = [requestmutableCopy];

            [mutableRequestsetValue:lastModifiedStrforHTTPHeaderField:@"If-Modified-Since"];

            request = [mutableRequestcopy];

        }

        returnrequest;

    }];

    SDWebImageDownloader.sharedDownloader.requestModifier=requestModifier;
上一篇下一篇

猜你喜欢

热点阅读