how can i save in userdefaults if my app has crashed
In my Universal-App i have some issues where the app crashes. I could not reproduce the cause of the crash so i want at least make the app "save" so that it can restart again if it has crashed. Problem is, if my app crashes, it can happen that it cannot be started again due to some messed up user defaults. So, if i could delete my user defaults after my app has crashed while starting, the user could at least use the app furthermore.
So far for my goals. Now i only n开发者_如何学Pythoneed to know how i can detect and save it, when my app has crashed during starting.
My first intention was to set a flag in user defaults when the app crashes and then ,if the flag is set, to reset the user defaults. But i don't know if - (void)applicationWillTerminate:(UIApplication *)application
Any suggestions would be welcome.
Greetings and thx in advance Maverick1st
What about setting a flag every time your app starts up and unsetting it when it terminates normally? That way you know if it is already set when the app starts, it crashed last time.
One of the things about abnormal exit is that is going to be, well, abnormal. It's usually not a great idea to rely on being able to do anything sensible in such cases.
Instead of trying to set a flag when you crash, which will at best be unreliable, how about instead setting it when you start and then unsetting it when you exit normally? That way it'll be left set if you haven't cleaned things up and you'll know next time you start.
One thought... wrap your main starting code in your app delegate in a @Try @Catch block to handle the exception causing the crash. Perform any last minute code there (like setting your flag).
精彩评论