5

我的 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();
}

对于在生产应用程序中实际替换 abort() 的内容,我有点不知所措。我认为没有任何简单的方法可以让用户的设备将错误发回给您。这里的标准做法是什么?

4

1 回答 1

5

我所做的取决于应用程序中发生的事情。如果可以回滚保存而不影响应用程序,则可以这样做。那将是非常罕见的。更有可能的是,您想让用户知道他们的保存失败。根据失败的原因,您可以提出重试或解释失败的原因。

它基本上取决于您的应用程序以及您如何最好地为用户服务。

于 2010-01-19T21:30:57.480 回答