I have searched around, but have yet to find an answer that doesn't direct me towards a 3rd party service. I do not need anything intricate, just to save a value in NSUserDefaults
so when the app opens next, I can display an alert saying the app has crashed.
Thanks.
Details
Solution 1
https://github.com/zixun/CrashEye/blob/master/CrashEye/Classes/CrashEye.swift
Full sample of solution 1
Solution 2. Crashlytics
Full sample of solution 2
Results
Lunch app again
Thanks to a little help from @RyanCollins, I was able to solve the problem myself. The function
applicationWillTerminate
in the App Delegate only runs when the app closes properly. The code to natively detecting an app crash looks like this.Globally Defined Variables
App Delegate
Root View Controller
The problem is, if the app has crashed, then it can't run code to write to NSUserDefaults.
The best solution I know of is to use PLCrashReporter (https://plcrashreporter.org)