iphone - 将图像存储到磁盘
我有一堆图像想要保存到我的应用程序中,但我担心会占用设备上太多空间。
有没有办法检查我占用了多少空间?我怎么知道什么时候我占用了太多空间而必须删除一些东西?
谢谢
I have a bunch of images that I want to save to my app but I'm worried about taking up too much space on the device.
Is there a way to check how much space I'm taking up? And how do I know when I am taking up too much space and I have to delete some things?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看计算文件夹的大小...,你会发现一些计算文件夹大小的方法。据我所知,设备上可以保存的数据量没有大小限制。但是,如果设备的光盘已满,保存数据将会失败。
看看 http://kdbdallas.com/2008/12 /27/maciphone-show-availble-useable-diskspace/ 了解如何查找可用磁盘空间。
您还可以使用 NSFileManager 的实例方法 attributesOfFileSystemForPath:error:。它返回一个字典,看看 键,尤其是 NSFileSystemFreeSize。
如果空间不足,当然应该删除文件,至少向用户提供一些有关应用程序使用了多少空间的信息。
Have a look at Calculate the size of a folder…, you'll find some ways to calculate the size of a folder. As far as I know there is no size limit to how much data you can save on the device. However if the device's disc is full saving data will fail.
Look at http://kdbdallas.com/2008/12/27/maciphone-show-availble-useable-diskspace/ on how to find out how much disk space is available.
You can also make use of NSFileManager's instance method attributesOfFileSystemForPath:error:. It returns a dictionary, have a look at the keys, especially NSFileSystemFreeSize.
If you run out of space you should delete files of course, at least present the user some information on how much space the app is using up.
实际上我最终使用了 Enormego 的 EGOImageLoading。
有关它的博客文章
Github链接
它显然是异步下载图像的,允许您在等待图像下载时使用占位符,并缓存图像,以便可以离线访问。
I actually ended up using EGOImageLoading from Enormego.
Blog post about it
Github link
It apparently downloads the images asynchronously, allows you to use a placeholder while waiting for the image to download, and caches the images so they're accesible offline.