我一直在使用AFNetworking 2.0。如果应用程序位于前台或来自后台,则缓存可以正常工作。但是当我杀死应用程序并重新打开它时,缓存就会被清除。有办法让它持久吗?感谢
答案 0 :(得分:0)
您可以使用 NSURLRequestReturnCacheDataElseLoad缓存策略从磁盘缓存:
目标-C
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:imageURL]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:60];
[imageView setImageWithURLRequest:imageRequest
placeholderImage:[UIImage imageNamed:@"placeholder"]
success:nil
failure:nil];
夫特
let imageRequest = NSURLRequest(URL: NSURL.URLWithString(imageUrl),
cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataElseLoad,
timeoutInterval: 60)
imageView.setImageWithURLRequest(imageRequest,
placeholderImage: UIImage(named: "placeholder"),
success: nil,
failure: nil)
来源:here