My application creates some temporary files that I need during its whole lifecycle. I need to dispose of those files eventually, so they don’t take up space on the device. I figured I could delete them when the application quits, but since the multitasking has been introduced the lifecycle is not as simple as it used to be. My main question is: When my application moves into background and gets killed later, does it receive applicationWillTerminate:
? Or is it just wiped from the memory?
I can’t do the cleanup when the application moves into background, since it could be backgrounded in the middle of an operation and would need the temporary files once it gets back on foreground. I think I could clean the files upon startup, but I am interested in the applicationWillTerminate:
behaviour anyway.
No, applicationWillTerminate:
is not called on multi-tasking enabled iOS 4 devices. When your app is terminated it usually means that the device is running out of memory, so even if is did get called there's no saying that you'd have enough memory available to complete the task anyway.
Apple recommend that you clean up when your app goes into the background. You can request extra time to do this if you need a few seconds (this is one of the few multi-tasking scenarios open to all applications).
Your other options would be to tidy up when the task is finished (whenever that is) or when the application is started. I guess there may be other permutations...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With