Ala*_*din 2 caching objective-c ios afnetworking-2
AFNetworking的缓存机制对我不起作用,我有500ko的大尺寸图像,我想缓存它.但每次我关闭应用程序并再次打开它时,我必须等待20秒才能加载图像,因此缓存系统不能正常运行,代码如下:
我试过了 :
[imageView setImageWithURL:[NSURL URLWithString:imageURL]
placeholderImage:[UIImage imageNamed:@"placeholder"]];
Run Code Online (Sandbox Code Playgroud)
然后尝试:
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:imageURL]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:60];
[imageView setImageWithURLRequest:imageRequest
placeholderImage:[UIImage imageNamed:@"placeholder"]
success:nil
failure:nil];
Run Code Online (Sandbox Code Playgroud)
NSURLCache不会默认写入磁盘,因此我们需要在app delegate中声明共享的NSURLCache:
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:2 * 1024 * 1024
diskCapacity:100 * 1024 * 1024
diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3621 次 |
| 最近记录: |