简体   繁体   English

我可以在我的 iPhone 应用程序中缓存多少张图片?

[英]how many images can I cache in my iPhone app?

I'm wondering how many images I can store in the iPhone documents directory so that I don't get any memory issues.我想知道我可以在 iPhone 文档目录中存储多少图像,这样我就不会遇到任何 memory 问题。 I'm torn between caching images or loading them from a webserver every time the user wants to access them.每次用户想要访问图像时,我都在缓存图像或从网络服务器加载图像之间左右为难。 There most likely won't be more than 10-20 images cached at any given time...在任何给定时间缓存的图像很可能不会超过 10-20 张...

Any thoughts?有什么想法吗?

You can probably cache as many files as available memory allows, but you absolutely should be safe having 10 - 20 images cached at any given time.您可能可以缓存 memory 允许的尽可能多的文件,但在任何给定时间缓存 10 - 20 张图像绝对应该是安全的。

BTW, instead of using the documents directory, why not consider using the cache directory as He (+1 to him?) suggests?顺便说一句,为什么不按照他(对他+1?)的建议考虑使用缓存目录,而不是使用文档目录?

Here is a related question that shows how to get the size of the directory . 这是一个相关的问题,它显示了如何获取目录的大小

There's a 2GB cap on the largest size of a single file in the /Documents folder. /Documents文件夹中单个文件的最大大小有 2GB 的上限。 Other than that, you can store as many images as you want.除此之外,您可以根据需要存储任意数量的图像。 iOS itself didn't put a limitation on how much space you can use on a device. iOS 本身并没有限制您可以在设备上使用多少空间。 So your space limit is the size of Flash on the device (ie 16GB, 32GB etc).因此,您的空间限制是设备上 Flash 的大小(即 16GB、32GB 等)。

You might consider use the /Library/Caches instead because iCloud will attempt to sync the Documents folder (if entitlements are configured).您可能会考虑改用/Library/Caches ,因为 iCloud 会尝试同步 Documents 文件夹(如果配置了权利)。 I heard App being rejected by review for excessive use of the Documents folder.听说App因为过度使用Documents文件夹被review拒绝了。 To get the path, call NSSearchPathForDirectoriesInDomains with NSCachesDirectory and NSUserDomainMask .要获取路径,请使用NSSearchPathForDirectoriesInDomainsNSCachesDirectory调用NSUserDomainMask

Though a user can determine the size of space you are occupying in System Settings.尽管用户可以确定您在系统设置中占用的空间大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM