How to know whether app is terminated by user or by iOS when restart app>
'By user' means "by Double-clicking Home Button and pressing - button". killed by user
'By iOS' means "app become background running state, and iOS terminate app after 10 mins"
iOS might terminate your app if system resources are low - if this happens, you will see
applicationWillTerminate
.It used to be that if a user killed the app (task manager, via the button double-click and then hits the red '-') it's a SIGKILL and applicationWillTerminate is not called. A report mid-2013 suggests this has changed and
applicationWillTerminate
now is called.You could use NSUserDefaults to write some state bit in
applicationWillTerminate
to note that this function was called and presumably that's a system kill rather than a user kill.If your app is in suspended state the
applicationWillTerminate
will never get called regardless who killed the app iOS or user.Your
applicationWillTerminate
will only call when your app is in background and it gets killed (either by iOS or user) the term background means that it is running in background not in suspended state.Just read this reference
Here is the table of various states