Reasons of applicationWillTerminate

Hi

We have a problem on some devices with the event applicationWillTerminate being called just after the app has entered background mode. I have myself logged the problem on a iPhone 6 and iOS 8.


The documentation says:

For apps that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the app. For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case. However, this method may be called in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason.


Our app indeed supports background execution, and it is for some reason terminated when user is pressing the Home button.


This does only occur on a very small amount of tested phones, but it can occur. Is there anyway to debug the real reason behind the decision to terminate it. Because without having the real reason, fixing it is extremely difficult.


Thanks!

--Anders

Answered by alindelof in 40495022

Correct, we build with a modern SDK and don't have UIApplicationExitsOnSuspend. And we are not using "older" devices, iPhone 5 and up.


For your information we are using Location Services to collect GPS data while the app is in the background. We are also using Cordova in our app.


I also assume memory pressure is the most likely cause. I have also seen examples when the app has been terminated without any notification previously in applicationWillTerminate (at least the I/O write to log the event is lost), and not even a report in the crash report logs.


- If there is no logged crash report after the crash/kill, for what possible reasons can iOS determine that an application must be terminated? Besides obvious reasons like using the multitasking UI and swipe up, and memory pressure.


We are trying to learn in what areas we can improve the app, to reduce the risk of being killed.


Thanks!

--Anders

The following assumes you're building with a modern SDK and you don't have

UIApplicationExitsOnSuspend
set in you information property list.

There's one easy way to trigger

-applicationWillTerminate:
, to wit, with your app in the foreground, bring up the multitasking UI and swipe up on your app.

Beyond that it's really up to the OS. Are the devices exhibiting this behaviour primarily older devices? I suspect that memory pressure is the most likely cause of the symptoms you describe.

Can you reproduce this in house? If so, do you see anything interesting in the system log?

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

Correct, we build with a modern SDK and don't have UIApplicationExitsOnSuspend. And we are not using "older" devices, iPhone 5 and up.


For your information we are using Location Services to collect GPS data while the app is in the background. We are also using Cordova in our app.


I also assume memory pressure is the most likely cause. I have also seen examples when the app has been terminated without any notification previously in applicationWillTerminate (at least the I/O write to log the event is lost), and not even a report in the crash report logs.


- If there is no logged crash report after the crash/kill, for what possible reasons can iOS determine that an application must be terminated? Besides obvious reasons like using the multitasking UI and swipe up, and memory pressure.


We are trying to learn in what areas we can improve the app, to reduce the risk of being killed.


Thanks!

--Anders

We have in particular one customer and also test user of the device where this crash is comig very often. Regular crashes, like a few times a day, is not uncommon on this particular device.


Since we have physical access to this device, is there in any way possible to determine the reason behind the kill?


Also, we did not receive any messages didReceiveMemoryWarning on any controllers before the kill (at least not during the last analyzed kills). And we haven't received any crash reports in "Diagnostis & Usage".


--Anders

Is there any particular utility (you recommend) that the test user can use to access the iOS System log?


Thanks!

--Anders

Right now the only option is Xcode. I used to point folks at iPhone Configuration Utility but, alas, that’s not longer supported. [I’m hoping that the new Apple Configurator 2 will support this but, alas, I haven’t had a chance to try it out yet.]

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Reasons of applicationWillTerminate
 
 
Q