2

I'm using SDWebImagePrefetcher to prefetch a list of images off my plist (about 100, max size 600kb) in order to save them (on disk possibily) for later use.

Point is that on simulator this is working fine, while on device, it's loading and caching only some of them and I honestly don't get why.

I know this because after prefetching them, i turn off WiFi connection and see if the images have been loaded correctly in the imageView (on detailView), and surprisingly there are only 1\5 of the images prefetched, even if the consoloe said it prefetched them all.

I tried to put in SDWebImagePrefetcher.m in method startPrefetchingAtIndex: this line of code

- (void)startPrefetchingAtIndex:(NSUInteger)index withManager:(SDWebImageManager *)imageManager
{
    if (index >= [self.prefetchURLs count]) return;
    _requestedCount++;

    [imageManager downloadWithURL:[self.prefetchURLs objectAtIndex:index] delegate:self options:self.options];
    [cache storeImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[self.prefetchURLs objectAtIndex:index]]]] forKey:[self.prefetchURLs objectAtIndex:index] toDisk:YES];

}

and then in my imageView class:

SDImageCache* cache = [SDImageCache sharedImageCache];
    UIImage* cachedImage = [cache imageFromKey:aString fromDisk:YES];

    if (cachedImage) {
        [imageView setImage:cachedImage];
    }
    else{
    [imageView setImageWithURL:[NSURL URLWithString:anUrl]
              placeholderImage:nil options:SDWebImageProgressiveDownload
                       success:^(UIImage *image) { [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; }
                       failure:^(NSError *error) {  [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; }];

    [imageView addSubview:activityIndicator];
    }

With no concrete results. Always working on simulator, not on device. Am I missing something here? Should I put some caching method in SDWebImagePrefetcher to store them on disk or what? I've being trying to make it work but failing every time.

4

1 回答 1

1

Seems like i found the issue.

I shouldn't set the option to cache ( [prefetcher setOptions:SDWebImageMemoryCacheOnly]; ) ,but I had to leave it in low priority, so now everything works perfectly!

于 2012-10-05T19:07:52.873 回答