Simulating Background App Termination on iOS devices
Recently I was helping my client to update their app so that some operation will be executed before the app is terminated. After few hours of coding, is time for testing… There will be 2 situations that we need to test:
- Force termination trigger by user.
- Background termination trigger by the system.
The 1st situation is pretty easy to test, just double tap the home button and swipe up to terminate the app.
But how do we test the 2nd situation? Can we ask Siri to do that for us? Obviously no… Can we run some resource heavy games and hope the system will trigger the app termination? Yes we can, but this method is not reliable and way too troublesome. 😭
After some Googling, apparently we can force the system to free up the RAM and indirectly triggering background app termination. Do note that this method can only work on a real iOS device and not the iOS simulator. Here’s what you need to do:
- Make sure your iOS device is at the home screen and unlocked.
- Long press the power button until you see “slide to power off”.
- Release the power button and long press the home button for about 5s (until you see your home screen reappeared).
That’s it! Try to run your app now, you will notice that your app has been terminated and relaunching.
This method really helped me when testing background termination on my client’s app. Hopefully this will be helpful to others iOS developer as well.
Please do not hesitate to hit the 👏 button if you like this article. 😄