iOS App崩溃时我们可以停止关闭应用程序吗 [英] Can we stop closing the application when iOS App crash

查看:183
本文介绍了iOS App崩溃时我们可以停止关闭应用程序吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了iOS App,因为如果我们遇到任何未知的崩溃,我想显示一条消息,例如对不起,某些事情出错了。同时,该应用未关闭。如果发生崩溃,它仍然会打开。

I have implemented iOS App, In that if we get any unknown crash i want to show one message like "sorry some thing went wrong". Meanwhile the App did not close. It still open if we get crash. Its a requirement from client.

推荐答案

简短答案:这不是一个好主意,应该不惜一切代价避免。说服提供此要求的人,不要执行此操作。

Short answer: This is not a good idea and should be avoided at all cost. Convince the person who provided that requirement that this should not be done.

长回答:当您的应用崩溃时,这意味着出现了严重错误。进入无法再保证任何东西的状态,最好立即退出应用程序(即使对于应用程序用户而言)。崩溃的原因可能是:

Long answer: When your app crashes, this means something went horribly wrong. It got into a state where nothing can be guaranteed any longer and it is better (even for the app user) to quit the app right away. The reasons for a crash could be:


  • 未处理的错误

  • 您正在尝试访问一些您无权访问的内存

  • 访问已取消分配的内存,但是您的应用程序代码认为它仍被分配给特定对象

  • 还有许多其他原因

  • an unhandled error
  • you are trying to access some memory that you don't have access to
  • accessing memory that is already de-allocated, but your app code thinks it is still allocated to a specific object
  • and many many more reasons

对于第一种情况,您可以在整个应用或全球范围内设置未处理的错误处理程序;这就是崩溃报告SDK的功能。由于其他原因,您需要设置信号处理程序(甚至是Mach异常处理程序)来获取那些信号处理程序。在这种情况下的一条规则是,在崩溃时,您不应该分配新的内存,仅仅是因为您不能保证可以使用或不会覆盖应用程序其他部分使用的内存,否则可能会导致用户数据的严重损坏,或者死锁设备,这意味着设备所有者必须重新启动设备。

For the first case you could setup unhandled error handlers across your app or globally; this is what crash reporting SDKs do. For the other reasons you need to set up signal handlers (or even Mach exception handlers) to get those. One rule in those cases is that at crash time you should NOT allocate new memory, simply because you have no guarantee that will work or would not overwrite memory used by other parts of your app which then could cause major corruption of the user's data, or deadlock the device which means the device owner has to restart it.

在崩溃时不允许分配任何内存意味着您无法使用任何Swift或Objective-C代码,因为分配新对象将分配新内存。而且,显示警报也可以做到,因为让应用程序继续运行也可以。您只能在崩溃时使用(异步安全)C方法的子集!

Not being allowed to allocate any memory at crash time means you can't use any Swift or Objective-C code, because allocating a new object WILL allocate new memory. And showing an alert will just do that as having the app continue to run will do as well. You can only use a subset of (async-safe) C methods at crash time!

所以故事的结尾是:


  • 很难检测到崩溃

  • 在崩溃之后更不会对用户数据造成可能的损坏

  • 保证应用程序能够继续运行而不会造成用户数据损坏或根本无法为用户使用而没有更多问题,这在运气方面

如果操作系统由于这种不安全的情况而决定您的应用程序应该退出(崩溃),则作为应用程序开发人员的您不应做出其他决定。

If the operating system decides that your app should exit (crash) because of such an unsafe scenario, you as an app developer should not decide otherwise.

这篇关于iOS App崩溃时我们可以停止关闭应用程序吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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