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

发布于 2024-08-18 09:37:31 字数 675 浏览 2 评论 0原文

我的 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() 。我认为没有任何简单的方法可以让用户的设备将错误发送回给您。这里的标准做法是什么?

I have quite a few places in my iPhone application with a line like this:

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

I'm sort of at a loss on what to actually replace abort() with in a production application. I don't suppose there's any simple way to allow users' devices to send the errors back to you. What's the standard practice here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南汐寒笙箫 2024-08-25 09:37:31

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

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

What I've done depends on what is happening in the application. If the save can be rolled back without affecting the application, you can just do that. That would be pretty rare. More likely, you are going to want to let the user know that their save failed. Depending on the cause of the failure, you can offer to try again or explain why it was invalid.

It basically depends on your application and how you would best serve the user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文