1、首先缓存图片,等待后面利用本地url来取
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
TTURLCache *cache = [TTURLCache sharedCache];
for (NSDictionary *item in results) {
if (![cache hasDataForKey:[item objectForKey:@"thumb_url"] expires:3000]) {
[cache storeData:[NSDatadataWithContentsOfURL:[NSURLURLWithString:[item objectForKey:@"thumb_url"]]] forURL:[item objectForKey:@"thumb_url"]];
}
}
});
2、利用本地url来取图片
TTURLCache *cache = [TTURLCachesharedCache];
NSMutableArray *photoResource = [NSMutableArrayarray];
for (NSDictionary *item in wallRequestResults) {
UIImage *imagePNG = [UIImage imageWithData:[cache dataForURL:[item objectForKey:@"thumb_url"]]];
NSString *tempURL = [[TTURLCache sharedCache] storeTemporaryImage:imagePNG toDisk:NO];
Photos *photo = [[Photos alloc] initWithURL:[item objectForKey:@"url"] smallURL:tempURL size:CGSizeMake(320, 480)];
[photoResource addObject:photo];
TT_RELEASE_SAFELY(photo);
}