替换aborts()以解决iPhone/CoreData中未解决的错误

And*_*ewO 5 iphone core-data abort

我的iPhone应用程序中有很多地方有这样的一行:

if (![context save:&error]) {
  /*
  Replace this implementation with code to handle the error appropriately.

  abort() causes the application to generate a crash log and terminate. 
  You should not use this function in a shipping application, although 
  it may be useful during development. If it is not possible to recover 
  from the error, display an alert panel that instructs the user to quit 
  the application by pressing the Home button.
  */

  NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
  abort();
}
Run Code Online (Sandbox Code Playgroud)

我对在生产应用程序中实际替换abort()的内容感到茫然.我不认为有任何简单的方法允许用户的设备将错误发送给您.这里的标准做法是什么?

Don*_*Don 5

我所做的取决于应用程序中发生的事情.如果可以回滚保存而不影响应用程序,则可以执行此操作.那将是非常罕见的.更有可能的是,您希望让用户知道他们的保存失败了.根据失败的原因,您可以提供再试一次或解释它无效的原因.

它主要取决于您的应用程序以及如何最好地为用户服务.

  • 我同意唐.至少你应该向用户提供一个警告,详细说明出了什么问题.也许是向您发送报告的选项,以便您可以在下一版本中解决问题.话虽如此,这些错误*应该*永远不会在野外发生.根据我的经验,如果进行了充分的测试,核心数据的错误几乎总是在开发中出现.我在Core Data中直接看到的唯一问题是迁移,通常是在桌面上. (2认同)