Search code examples
iosios-simulator

How can I simulate app being killed in background?


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.


Solution

  • 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.)