初始coredata保存冻结应用程序

初始coredata保存冻结应用程序

本文介绍了初始coredata保存冻结应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用程序使用coredata与三个不同的模型。数据从服务器的json feed中提取,然后保存。每个API调用在使用NSOperationQueue的线程上运行,因此它们从不同时执行。在最后调用我保存到最大的模型被存储它是在保存发生后,应用程序挂起。 UI变得无响应,调试器没有给出错误。这只发生在应用程序的第一次加载,之后每个后续负载运行完美。我试图加载只有最后的api调用,错误仍然发生。我收到委托回调controllerDidChangeContent:并且在方法中什么都不做。我被骗了。

I have an iOS application using coredata with three different models. The data is pulled from a json feed from a server then saved. Each API call is run on a thread using NSOperationQueue so they never execute at the same time. On the final call I save to the largest model being stored it is after the save happens that the application hangs. The UI becomes unresponsive and the debugger gives no errors. This only happens on the first load of the app, afterwards every subsequent load runs perfect. I have tried loading only the final api call and the error still happens. I receive the delegate callback controllerDidChangeContent: and do nothing in the method. I am stumped. Thank you folks for you assistance.

推荐答案

这是冻结你的应用程序,因为你很可能将保存合并到main NSManagedObjectContext 通过 NSManagedObjectContextDidChangeNotification 。这是iOS 5.0之前的已知限制。

It is "freezing" your app because you are most likely merging the save back to the main NSManagedObjectContext via the NSManagedObjectContextDidChangeNotification. This is known limitation prior to iOS 5.0.

您可以更新到5.0并使用添加的父子MOC设计,或者您可以跳过上下文合并, -reset 主上下文,并强制它保存后重新加载相关数据。

Either you can update to 5.0 and use the parent child MOC design that was added or you can skip merging the contexts and -reset the main context and force it to reload relevant data after the save.

这篇关于初始coredata保存冻结应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 13:18