Disclaimer: I am not working for an outsourcing company. I am currently working for Beijing Honghuanglan Education Institution, whose products include bamboo Pocket Child Care, Honghuanglan Parent-Child Park and other platform service apps. As for the daily work of Zuduo parenting, IF it is due to the developers, I can’t refute. the operation of the company really doesn’t listen to me, and I once made relevant suggestions, but nothing happened. I worked in Red, Yellow and Blue before I graduated from university. Now I am ready to quit. If there is a suitable company, please contact me, thank you.
- Before using a third-party application, take the time to read the source code, even if it’s a simple upgrade. After all, no one changes code for no reason
- If it can be encapsulated simply, granularity can be controlled by itself, but good granularity control is effective for system upgrade, code reconstruction and expansion
1, SDWebImage pit (probably many people have said, but their own sorting, save for their own use, to provide others with another idea is good)
- In SDWebImage 4.0.0, the SDImageCacheConfig class has been added. This class contains configuration items for Cache, which can be changed if needed.
-
Decompressimages official: Decompressing downloaded or cached images can improve performance but use a lot of memory. The default is YES (unzip), but if your project is plagued by high memory usage of images or has flashbacks, it is strongly recommended that you set this to NO. A slightly slower response is acceptable compared to the flashbacks
-
ShouldCacheImageInMemory Whether to cache in memory. Those who have used SD know that the SD cache strategy is to cache the memory first, and the system’s fastest response is then cached to Disk to generate a specific key value. The next time you request the same URL, first go to the memory to check whether the cache exists, if so, directly display, and check whether the Disk does not exist, if not, write to Disk again. However, if the quality of the images in the project is uneven and most of them are large, it is not recommended to cache them in the disk. Caching them in the disk will occupy a large amount of memory, and the program will blink back before it is too late to release them. Therefore, perform related Settings based on services
Code sample
SDImageCacheConfig.m _shouldDecompressImages = NO; _shouldCacheImagesInMemory = NO; PS: If you are a company with high performance requirements, FPS must be above 60, response time control is extremely strict and so on, I believe that you will not only start from iOS, but also optimize in many aspects. Sometimes the mobile terminal needs services that cost a lot to complete, and just write two more lines of code on the back-end can solve the problem. 2. SDWebImageDownloader and SDWebImageManager still have the phenomenon of loading large images and occupying high memory * Manager has called Download internally. Download internal call SDWebImageDownloaderOperation, so if there is a memory surge can directly positioning for the image to look inside operation, where is the code. At the same time, use Instruments to check the memory usage and locate the specific code location. In the past, SD did not do any processing on the original image and directly converted to data, resulting in a direct increase in memory. 1. AFN will be used by most developers, and will be packaged according to the business. I used to do the same, and it worked well every time, until THIS project, I was completely defeated by the project. At least 1500 pictures, 50 PDF files and more than 40 video files in the project require offline caching and one-click caching. Regardless of whether the requirements are reasonable or not, we can definitely do it. As it turned out, I did it, and I did it all right. No card, no flash back, smooth operation. * AFN with YYCache cache idea is that each request, first read the local cache data according to the URL, the existence of the display, after the successful request, asynchronously save the successful data, return the successful data again, refresh the view. YYCache will automatically process the internal cache logic, specific can see YYCache source part, very good understanding, so at least do not write bad SQL statements in the database, but also consider the database read and write performance, all by automatic processing, save a lot of trouble. ! [AFN & YYCache.png](http://upload-images.jianshu.io/upload_images/1226381-a66ac4698299a48f.png? ImageMogr2 /auto-orient/strip% 7cImageView2/2 /w/1240) this is just a simple way to provide some ideas about caching data. There are many things to be improved in the future. 1. AFN also has its own support for UIkit framework, but it has not been used by many people. But there are also redeeming points. * Compared with SDWebImageDownloader, the memory occupied by AFN is less than SD when the same large image is requested, and there is no memory surge. The memory control performance is good, and it is relatively stable all the time. Occupancy release is good. However, cachePolicy Settings must be set well, Because if requestCachePolicy set to NSURLRequestReturnCacheDataElseLoad or NSURLRequestReturnCacheDataDontLoad, New data returned by the server is not displayed. Fortunately, the AFN AFNetworkReachabilityManager provides a callback method of network switch can be set in the callback methods. This was the strategy I adopted in my application at the beginning. However, because my resource file is too large, and the network is too unstable, it will cause the cache read and write chaos. It may be writing to the cache at this time, but the network breaks down and starts to read the cache, which is difficult to deal with. So FOR this situation, I made the following substitution solution. 2. AFN file download function The types of resource files have been determined, only images, PDF and Video resource files, download by queue group, first request image files, download PDF files after all image files are downloaded successfully, and then download Video files. Because the Video file is very large and takes a long time, as well as the business logic, it is put in the last download. ! [dispath_group queue download file.png](http://upload-images.jianshu.io/upload_images/1226381-c96a94068484ca3c.png? ImageMogr2 /auto-orient/strip% 7cimageView2/2 /w/1240) [AFNDownload method encapsulation. PNG](http://upload-images.jianshu.io/upload_images/1226381-24461533f56dbe2f.png? ImageMogr2 /auto-orient/strip% 7cimageView2/2 /w/1240) It is important to http://cyznres.rybbaby.com/20170508155721332_75.jpg?imageView2/1/w/150/h/130/q/100/format/png http://cyznres.rybbaby.com/20170508155721332_75.jpg?imageMogr2/format/jpg/size-limit/5120k! Because of the way AFN access to the file name is directly obtained ` response. SuggestedFilename ` above the picture of the two links file name is the same, but access to the size of the image quality is different, the former as the thumbnail of the latter as the Gao Qingtu, so make sure must be placed under a different path to save. This is important * For handling failed downloads, MY approach is to add the URL to the Fails array after the download fails, and when all files have been downloaded, traverse the Fails new group for downloading up to three times. AFN & SDWebImageCache read file! [Method of displaying pictures.png](http://upload-images.jianshu.io/upload_images/1226381-e20ca8ff4a977a15.png? ImageMogr2 /auto-orient/strip% 7cImageView2/2 /w/1240) * CimageView2/2/ auto-orient/strip% 7CImageView2/2 /w/1240 Direct read local file display * file is not downloaded, using SD display, and cache to Disk four, the overall flow chart! [AFN & SDWebImage with flowchart. PNG](http://upload-images.jianshu.io/upload_images/1226381-a1d874e791507842.png? imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)Copy the code