[英]how can I hold initial data when introducing an iPhone app?
I am developing an iPhone app which retrieves information via NSUrlRequest and displays through UIWebView. 我正在开发一个iPhone应用程序,该应用程序通过NSUrlRequest检索信息并通过UIWebView显示。
I want to hold initial data (such as HTML pages, images) as a cache so that users of my app can access to data without network costs at the first time. 我想保留初始数据(例如HTML页面,图像)作为缓存,以便我的应用程序用户可以在第一时间访问数据而无需支付网络费用。 Then, if data on my web server are updated, I would download them and update the cache. 然后,如果更新了我的Web服务器上的数据,我将下载它们并更新缓存。 For performance issues, I think it is better to store data on file system than on core data. 对于性能问题,我认为将数据存储在文件系统上比存储在核心数据上更好。 Yet, I think it's not possible to release a new app writing data on disk. 但是,我认为不可能发布一个新的将数据写入磁盘的应用程序。
So, I am about to store initial data(or initial cache) at Core Data, and when users launch my app for the first time, I would copy the data to disk (like /Library folder). 因此,我将在Core Data中存储初始数据(或初始缓存),当用户首次启动我的应用程序时,我会将数据复制到磁盘(如/ Library文件夹)。
Is it, do you think, a good approach? 您认为这是个好方法吗? Or,...hmm, can I access to Core Data using NSUrlRequest? 或者,...嗯,我可以使用NSUrlRequest访问Core Data吗?
One more question, I might access to file system using NSURL, which is the same as to data on the Web. 还有一个问题,我可能会使用NSURL访问文件系统,这与Web上的数据相同。 (right?) My app would compare version of the cache with version of data on my web server, and if it's old, retrieve new data. (对吗?)我的应用程序会将缓存的版本与Web服务器上的数据版本进行比较,如果过旧,则检索新数据。 and my app will access only to file system. 而且我的应用只能访问文件系统。 All data are actually HTML pages including script, and images. 所有数据实际上都是HTML页面,包括脚本和图像。 And, I want to cache them. 而且,我想缓存它们。
could you suggest a better design? 你能建议一个更好的设计吗?
Thank you. 谢谢。
Is it, do you think, a good approach? 您认为这是个好方法吗? Or,...hmm, can I access to Core Data using NSUrlRequest? 或者,...嗯,我可以使用NSUrlRequest访问Core Data吗?
No. 没有。
One more question, I might access to file system using NSURL, which is the same as to data on the Web. 还有一个问题,我可能会使用NSURL访问文件系统,这与Web上的数据相同。 (right?) My app would compare version of the cache with version of data on my web server, and if it's old, retrieve new data. (对吗?)我的应用程序会将缓存的版本与Web服务器上的数据版本进行比较,如果过旧,则检索新数据。 and my app will access only to file system. 而且我的应用只能访问文件系统。 All data are actually HTML pages including script, and images. 所有数据实际上都是HTML页面,包括脚本和图像。 And, I want to cache them. 而且,我想缓存它们。
Yes. 是。
But you could also be more clever. 但是您也可以更聪明。 And by "more clever" I mean "Matt Gallagher." “更聪明”是指“马特·加拉格尔”。 Take a look at his very interesting approach in Substituting local data for remote UIWebView requests . 看看他在将本地数据替换为远程UIWebView请求时非常有趣的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.