Take a look at the iOS Application States.
applicationWillTerminate: looks like the obvious choice but it is not guaranteed to be sent to applications which run in the background. Your best bet would be applicationDidEnterBackground:
Basically, when your app is backgrounded, write out that it is in the background state. When it is foregrounded, write out that it is in the foreground state. When your app launches, check whether the background flag is set - if so, the app was killed while in the background - either by the os, the user, or lack of power. It's not ideal, but is the best you can do on an iOS device - since an application can go from "not running" to "terminated" without executing any code, you can only rely on background / foreground.
You should get applicationDidEnterBackground: called for every situation except for sudden power loss / destruction.