开发者

Better way of updating images bundled with the app

开发者 https://www.devze.com 2023-03-07 13:45 出处:网络
In our iOS app we have close to a hundred image files in resources bundle. Now we want to make them network based since the images may change (updated/no longer needed/additions) at any time. We are d

In our iOS app we have close to a hundred image files in resources bundle. Now we want to make them network based since the images may change (updated/no longer needed/additions) at any time. We are debating at what approach would be optimal. From what I have read, I understand that the resource bundle will not be editable on the device. So, when I start the app, I will check from the server if there are any image updates. If so, I will download the changed images and then save them to documents directory. Then in the app, for every image, I will basically have to check if开发者_Go百科 it is in the resources bundle, then grab it from there. Else pick it from documents directory and display it.

Another approach is I don't have anything in the resources folder, I download all images on app launch from the server and store them to documents directory and then on, download the changed files at subsequent app launch. Here I am eliminating the check on resources folder if an image is present or not and my app bundle size would be reduced.

The third approach would be to copy the files from my resources directory to the documents directory on first launch and thereafter continue from documents directory.

Any suggestions on what would be a better approach or all of them would be similar from the performance point of view?


IMO, option three offers the best balance between eliminating needless code and preloading as much data as possible. You don't want to make the user wait for 100 image downloads when the app starts the first time, so pre-load as many as possible. The copy code is simple and will only be used once. So that eliminates the runtime checks you'd have to do with the other options.


No worries, performance will not be an issue, unless you use a particularly unwise image lookup algorithm.

Filesystem traversal should be pretty fast for such a small amount of files.


Before implementing something yourself, I would recommend looking at something off the shelf for Image Caching. Namely EGOImageView from EnormEgo.

I have used it in several applications which are dependent on grabbing images from URLs. It handles everything for you, you just set up a 'background' image for it to show while it goes about it's business of grabbing the URL based image in the background. The second time you use it, it's available immediately. Definitely gets my vote for ease of use...

p.s. it's free to use

0

精彩评论

暂无评论...
验证码 换一张
取 消