Save space: Batch resize down all @2x images for old iPhones/iPads/iPods on first launch

元气小坏坏 提交于 2019-12-24 09:46:10

问题


The issue with this: iphone 4 - loading images x old devices

is that we end up filling our apps with double content. Ie a user has to download both the 2x size and the 1x sized image to his device, but will eventually only use one of them and the other one will be a waste of download time etc.

So I thought, in some cases it could be okay with just filling your app with the high res images (@2x), and on app launch (in the app delegate, before displaying the window... or something), you could batch scale all @2x images down for low res screen devices. When scaled down, you save those files to the device's documents and/or cache folder, and delete the original @2x images. How about that, did anyone do it already? (My googles, they do nothing) Any downsides to this? Will Apple smack me somewhere for doing this? etc...


回答1:


You definitely could batch scale those @2x images and save the scaled files to the documents folder. That would save download time, and use the same amount of space as bundling everything with your application, at the cost of some added complexity. I don't think that deleting the original @2x images is possible, however, or worth it even if it were - there's the possibility of moving apps and user data between devices. It would be the best just to choose the right data based on resolution, once you have them both. And I don't see much reason for Apple to smack you for doing this.

Oh, and of course, if you really have a lot of data, in the order of hundreds of megabytes, doing two versions of the app might make sense (in the vein of Rage, for example).




回答2:


I'm gonna answer my thoughts for now.

  • when doing a batch, you have to save the images to the cache/documents folder or something like that. Which means, any image specified in IB will still not be found by low res devices, possibly they won't be found with using the normal imageNamed etc either (not sure about this yet). Might be a fix for this, or I might have to fiddle with adding the images manually in viewDidLoad. Smells messy. Might work, with a good solution...

  • might be troublesome with app updates. As app updates are slow to publish (sorry Apple, yes, updates are slow to publish). With an update you probably would want to erase the cache folder, to make sure old images that were changed/removed with the update aren't still lingering in the cache. The caching would need to be supervised with some kind of versioning. Like check current app version, and if caching has been done for this version. If not, refresh the cache, kind of flow.



来源:https://stackoverflow.com/questions/5002774/save-space-batch-resize-down-all-2x-images-for-old-iphones-ipads-ipods-on-firs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!