Sdwebimage The process of loading pictures:
Sdwebimage supports asynchronous image download + cache, providing uiimageview+webcacha category for ease ofuse. Record The flow of sdwebimage loading pictures.
- Entrance setImageWithURL:placeholderImage:options: will show Placeholderimage first , then Sdwebimagemanager start processing the picture based on the URL .
- Enter Sdwebimagemanager-downloadwithurl:delegate:options:userinfo:, to Sdimagecache from the cache to find whether the picture has been downloaded QueryDiskCacheForKey:delegate:userInfo:.
- First from the memory picture cache to find if there is a picture, if there is already a picture cache in memory,sdimagecachedelegate callback imageCache:didFindImage:forKey:userInfo: to Sdwebimagemanager.
- Sdwebimagemanagerdelegate callback webimagemanager:didfinishwithimage: to Uiimageview+webcache and other front-end display pictures.
- If no memory is in the cache, the build nsinvocationoperation is added to the queue to start looking for pictures from the hard disk if it is already cached.
- try to read the picture file according to Urlkey in the hard disk cache directory. This step is performed at Nsoperation , so the callback notifydelegate is returned to the main thread :.
- If the previous action reads a picture from the hard disk, the picture is added to the in-memory cache (if the free memory is too small, the memory cache is emptied first). sdimagecachedelegate callback imageCache:didFindImage:forKey:userInfo:. And then callback the display image.
- If the picture is not read from the hard disk cache directory, the picture is not present in all caches, the picture needs to be downloaded, and the callback ImageCache:didNotFindImageForKey:userInfo:.
- Share or regenerate a downloader sdwebimagedownloader start downloading pictures.
- Image download by nsurlconnection to do, to achieve the relevant delegate to determine the picture download, download complete and download failed.
- Connection:didreceivedata: The use of ImageIO to download the progress by the picture loading effect.
- Connectiondidfinishloading: After the data download is finished, give Sdwebimagedecoder to do the image decoding processing.
- The image decoding process is done in a nsoperationqueue and does not slow down the main thread UI. If there is a need to download the image two times, it is best to complete here, the efficiency will be much better.
- In the main thread notifydelegateonmainthreadwithinfo: announce the decoding complete,imageDecoder:didFinishDecodingImage:userInfo: Callback to Sdwebimagedownloader.
- Imagedownloader:didfinishwithimage: callback to Sdwebimagemanager tell the picture download complete.
- Notify all downloaddelegates Download complete, callback to show the image where needed.
- Save the picture to Sdimagecache , the memory cache and the hard disk cache are saved at the same time. Writing files to the hard disk is also done in a separate nsinvocationoperation to avoid slowing down the main thread.
- Sdimagecache Registers some message notifications at initialization time, cleans up the memory image cache when the memory is warning or back to the background, and cleans up outdated images when the app is finished.
- Sdwi also offers Uibutton+webcache and Mkannotationview+webcachefor ease of use.
- Sdwebimageprefetcher can pre-download images for later use.
Third-party library sdwebimage The process of loading pictures