I know there have been questions regarding this but I haven't found the answer to this specific question.
In both cases, i.e, user killing the app explicitly or system killing the app (after ~10 minutes of being in background), applicationWillTerminate is called. I want to be able to differentiate between the two. Is it possible in iOS7?
            Asked
            
        
        
            Active
            
        
            Viewed 363 times
        
    2
            
            
        
        Shwethascar
        
- 1,142
 - 9
 - 18
 
- 
                    In iOS 4+ the applicationWillTerminate won't be called if you didn't set the UIApplicationExitsOnSuspend key. So for this question it is not possible. For reference : http://stackoverflow.com/questions/14291910/which-event-when-i-close-app-in-ios/14291944#14291944 – Midhun MP Apr 22 '14 at 19:02
 
2 Answers
1
            
            
        The difference is that applicationDidEnterBackground will be called ~10 minutes before applicationWillTerminate if it is the system is killing the app. I guess you could use a timer
        Zia
        
- 14,622
 - 7
 - 40
 - 59
 
- 
                    It could be that the user killed the app ~10 minutes after the app was in background too. I'm beginning to think there's no proper way to differentiate between the two. – Shwethascar Apr 22 '14 at 19:00
 - 
                    Yeah, I don't think there is one. But that should work about most of the time. Why do you need to know this anyways? – Zia Apr 22 '14 at 19:02
 - 
                    I need to handle the two cases differently. Mainly because of the alerts I need to show and handle other functions of the app accordingly. – Shwethascar Apr 22 '14 at 19:04
 - 
                    2@Shwethascar: it is not possible in iOS 4+, please check my above comment. If you didn't set the `UIApplicationExitsOnSuspend` key the `applicationWillTerminate` won't be called. If you set that key, then the won't will be closed immediately if user press the home button. – Midhun MP Apr 22 '14 at 19:08
 - 
                    1I don't think you should need to know the difference. If you do, it means that you are probably not following apple guidelines. – Zia Apr 22 '14 at 19:08
 - 
                    Just for clarification, for others too, if the app crashes (other than user killing it explicitly or system killing it after 10 mins), `applicationWillTerminate` doesn't get called? – Shwethascar Apr 22 '14 at 19:15
 - 
                    @MidhunMP That is true if I need the app to be killed as soon as it gets suspended (like pressing the home button). But I was referring to the case where after it is in the background the user kills it explicitly versus the system killing the app after 10 mins in the background. – Shwethascar Apr 22 '14 at 19:17
 -