简体   繁体   English

我应该将图像保存到iOS App的本地存储中吗?

[英]Should i save images to local storage in iOS App?

I am working on a project where i want to make the data, text, images available in offline mode as well. 我正在一个项目中,我也想使数据,文本,图像也可以在离线模式下使用。

I fetch data from a web-service which includes image urls and other data. 我从Web服务中获取数据,其中包括图像URL和其他数据。 I store the text data in core data entities, however i don't save images locally but fetch them in realtime. 我将文本数据存储在核心数据实体中,但是我不会在本地保存图像,而是实时获取图像。

To view images in offline mode i will have to save them to local storage. 要以离线模式查看图像,我将不得不将其保存到本地存储中。 However i am wondering if it would be the right approach. 但是我想知道这是否是正确的方法。 Saving images to local may possibly eat up a lot of storage on user's device. 将图像保存到本地可能会耗尽用户设备上的大量存储空间。

What is the best approach to address this problem? 解决此问题的最佳方法是什么?

Should i save images to local or should i fetch them on run time only? 我应该将图像保存到本地还是仅在运行时获取它们?

Use NSCache. 使用NSCache。 With NSCache you can set a limit to how many images and so on are cached. 使用NSCache,您可以设置缓存数量的限制。 See Apple's documentation for more details: https://developer.apple.com/reference/foundation/nscache?language=objc 有关更多详细信息,请参阅Apple文档: https : //developer.apple.com/reference/foundation/nscache?language=objc

Edit: Never mind NSCache, just save the images as files. 编辑:不用管NSCache,只需将图像另存为文件即可。 NSCache can still save you network usage and allow your app to be more responsive, but it is not what you want. NSCache仍可以节省您的网络使用量,并允许您的应用程序具有更高的响应速度,但这不是您想要的。

Should i save images to local or should i fetch them on run time only? 我应该将图像保存到本地还是仅在运行时获取它们?

This question for you , you should decide what you need or what is will be more suitable for your app . 对于您这个问题,您应该确定需要什么或将更适合您的应用程序。 at any way if you want to cache images i suggest to use this library SDWebImage 无论如何,如果您想缓存图像,我建议使用此库SDWebImage

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

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