I believe because of the new "Scene" way of doing things, this is no longer an option. Just making sure that is correct. I read on Stack Overflow that you can change the behavior of the entire app, sort of making it like the old way.
I think it started with deleting the "Application Scene Manifest" from the info. That seems extreme, so I'm not sure I would want to go there. So I tested the above on a real project. In this project, when you swipe up the home button, it goes into the background and stays running and I confirmed that it stays running.
So, applicationWillTerminate is called when a user terminates the app without switching it to background mode: the app is active, the user makes double press on Home button and throws out the app.
But if a user switches the app to the background at first, and then after this tries to terminate the app, applicationWillTerminate will not be called. Starting in iOS 4, the practical answer is "never. You can't assume that it will ever be called. Normally what happens is that your app gets moved to the background when the user presses the home button and then a few seconds later it shifts to the "suspended state" Still in memory but not receiving any CPU time.
Once your app is in the suspended state the system can terminate it at any time without warning usually due to memory pressure. When you are suspended you don't get the applicationWillTerminate call before being killed. You should assume that when you get a applicationDidEnterBackground: message, you are going to be suspended shortly after, and die while suspended.
Get your affairs in order save app state. Improve this answer. Stephen Darlington Stephen Darlington Where does it say that it gets called when you close it from the multi-tasking dock?
It says the exact opposite. It says that it is generally not called. I interpreted the 'may' the other way.. I guess then I won't be able to do the house cleaning functions I intended to do. This is kind of odd isn't it?
That is what was terminating my app. Not sure how that setting got put in there, but thanks for pointing it out. Andrew Hershberger Andrew Hershberger 4, 1 1 gold badge 24 24 silver badges 35 35 bronze badges.
I also recognize that this is not a definitive description of when -applicationWillTerminate: is called, nor is it guaranteed to be comprehensive. Even so, I found it useful to know that it is possible for it to be called even in apps that support background execution.
That makes some sense -- an app with a background task running could use the In most cases, -[UIApplication applicationWillTerminate:] will never be called, unless the application is terminated by the iOS system such as memory not enough.
So when crashed or killed by the user, it will not be called. If you directly double click on Home button while the app is working in foreground and swipe up and kill the app in App Switcher, applicationWillTerminate: is called, regardless of there is a background task or not.
But, if you click Home button only once, and make the app go into background first, and then double click Home button, swipe up and kill the app later, applicationWillTerminate: will be called only if there is background process is going on. Otherwise it will not be called.
As I know, there are 3 situations that your application will die. Dropped by the system, such as memory not enough, you can do something in -[UIApplication applicationWillTerminate:] , in which case, we do NOT know whether applicationWillEnterBackground: has been called; Crashed, nothing can be done except using some kind of Crash Reporting Tool. DawnSong DawnSong 3, 1 1 gold badge 30 30 silver badges 37 37 bronze badges. BaSha, you are correct for Xcode 9 and iOS However, it did as what I said when I answered this question.
BaSha No, it is not. Only sometimes. The documentation clearly states that this cannot be reliably used.
But it is not being called when first application is entered in background state pressing home button and then user terminates application. Thanks, Neil. Asked by nvannote. Copy to clipboard Share this post. Copied to Clipboard. Add a Comment. Accepted Answer. Posted by sstanley. Post marked as solved. Does applicationDidEnterBackground get called? Why do you think your app 'terminates'?
Posted by PBK. Regards, Neil. Posted by nvannote. I observed the same in a Swift project, with some strange behavior. Conf: OSX I started again, making incremental changes from the empty project never printed until I loaded the request.
0コメント