[英]iOS Caching images with AFImageCache doesn't seem to work
我正在嘗試使用AFImageCache緩存從URL加載的一些圖像,但沒有成功...我不確定如果我做錯了什么,如果您曾經使用過此庫,是否會喜歡您的意見。
我從NSURLRequest獲取圖像,然后將其緩存如下
UIImage *img; //This image is a png icon returned from the server
NSData *imgData = UIImagePNGRepresentation(img); // Always checking length to make sure its more than 0, and it is
[[AFImageCache sharedImageCache] cacheImageData: imgData
forURL: myURL
cacheName: @"IconCache"];
在下一次運行時,我將嘗試檢查圖像是否已緩存,但由於某些原因始終會變為nil
。
UIImage *myIcon = [[AFImageCache sharedImageCache] cachedImageForURL: myURL cacheName: @"IconCache"];
NSLog("%@", myIcon); // output (null)
有任何想法或想法嗎? 謝謝。
您正在使用哪個版本的AFNetworking? AFImageCache
以前, AFImageCache
已從公共API中刪除。 如果要進行圖像緩存,請使用NSURLCache
,它在系統級別緩存所有網絡響應。 AFImageCache
一直只是一個臨時緩存,用於提高滾動視圖中圖像加載的性能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.