使用CoreData在iPhone上导入大型数据集 [英] Importing large datasets on iPhone using CoreData

查看:107
本文介绍了使用CoreData在iPhone上导入大型数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面对非常恼人的问题。我的iPhone应用程序从网络服务器加载它的数据。数据作为plist发送,当解析时,它需要使用CoreData存储到SQLite数据库。



问题是,在某些情况下,这些数据集太大),导入过长。更多的是,当iPhone尝试挂起屏幕时,Watchdog杀死了应用程序,因为它仍然处理导入,并且不响应高达5秒,因此导入永远不会完成。



我根据有效导入数据文章使用了所有推荐的技术 http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/CoreData/Articles/cdImporting.html 和其他与此相关的文档,但仍然非常缓慢。 p>

解决方案我想要的是让应用程序暂停,但允许导入在后面运行(更好的一个),或者防止尝试挂起应用程序。



任何有关如何克服这些问题的提示都非常感谢!
感谢

解决方案

首先,如果你可以打包数据与应用程序是理想的。



但是,假设您不能这样做,那么我将执行以下操作:



  1. 在后台主题中一次导入一个文件。

  2. 导入并保存文件后,请删除导入文件。

  3. 启动时,查找等待处理的文件,并从中断的位置继续。 / li>

理想情况下,使用应用程序发送数据远远少于工作,但第二个解决方案将工作,您可以微调数据分解


I'm facing very annoying problem. My iPhone app is loading it's data from a network server. Data are sent as plist and when parsed, it neeeds to be stored to SQLite db using CoreData.

Issue is that in some cases those datasets are too big (5000+ records) and import takes way too long. More on that, when iPhone tries to suspend the screen, Watchdog kills the app because it's still processing the import and does not respond up to 5 seconds, so import is never finished.

I used all recommended techniques according to article "Efficiently Importing Data" http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/CoreData/Articles/cdImporting.html and other docs concerning this, but it's still awfully slow.

Solution I'm looking for is to let app suspend, but let import run in behind (better one) or to prevent attempts to suspend the app at all. Or any better idea is welcomed too.

Any tips on how to overcome these issues are highly appreciated! Thanks

解决方案

First, if you can package the data with the app that would be ideal.

However, assuming you cannot do that then I would do then following:

  1. Once the data is downloaded break it into multiple files before import.
  2. Import on a background thread, one file at a time.
  3. Once a file has been imported and saved, delete the import file.
  4. On launch, look for those files waiting to be processed and pick up where you left off.

Ideally sending the data with the app would be far less work but the second solution will work and you can fine-tune the data break up during development.

这篇关于使用CoreData在iPhone上导入大型数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆