Can we stop closing the application when iOS App crash

前端 未结 1 493
無奈伤痛
無奈伤痛 2021-01-29 12:26

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 i

相关标签:
1条回答
  • 2021-01-29 12:49

    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

    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.

    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!

    So the end of the story is:

    • detecting a crash is hard
    • not causing possible damage to user data after a crash is even harder
    • guaranteeing the app will continue to run without causing damage to user data or being usable to the user at all without more problems is in the area of luck

    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.

    0 讨论(0)
提交回复
热议问题