I'm trying to verify that my app (App1) behaves correctly when it is shut down by the system after it launches another app (App2). Is there any way to simulate or force this behavior?
Telling the simulator to simulate a memory warning while App2 is running doesn't do anything until App1 is brought back to the foreground. Would killing App1 from the debugger simulate the same sequence of app events?
EDIT: My app is placed in the background when it launches a second app to handle a file. This second app then relaunches my app, and I'm trying to verify that my app behaves correctly when the system has shut it down while the second app is executing.
If limits are exceeded by an app with background processing, for a certain time, iOS will kill the app. BGProcessingTask gives an unrestricted few minutes to your app to run processing tasks in the background, while the device charges overnight.
First press Shift+Command+ H twice. This will open up all the apps that are currently open. Swipe left/right to the app you actually want to close. Just Swipe Up using the Touchpad while Holding the App would close the app.
At the same time, didReceiveMemoryWarning is invoked for the app. At this point, so that your app continues to run properly, the OS begins terminating apps in the background to free some memory. Once all background apps are terminated, if your app still needs more memory, the OS terminates your app.
Enable Settings - Developer - Fast App Termination on the device:
This will terminate, instead of suspend, your app when they're backgrounded. This is useful primarily for testing state restoration logic.
As the other answers note, you can immediately end your app by force-quitting it or by stopping the debugger. Your app will get no warning in those cases.
If you're looking to test your applicationWillTerminate
methods, set UIApplicationExitsOnSuspend
to YES
in your .plist and then switch apps or press the home button. Make sure you set the key to a Boolean, not the string "YES".
Yes, if your app is in the background already. An app killed by the system while in the background is terminated with no warning-- no app delegate methods are called, no state changes are made-- which is exactly what happens when you do a debugger stop while the app is in the background. (This presupposes that you've already put your app in the background by clicking the home button on the simulator or Cmd-Shift-H)
(As @Inafziger notes, you can also get the same effect by using the simulator's interface to force quit the running app.)
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