How can I simulate app being killed in background?

后端 未结 4 1090
小蘑菇
小蘑菇 2021-02-05 01:21

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 be

相关标签:
4条回答
  • 2021-02-05 01:39

    iOS 14.5 and Later

    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.


    iOS 14.4 and Earlier

    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".

    0 讨论(0)
  • 2021-02-05 01:49

    I know this is a couple of years old, but wanted to share if anyone else is looking into this now. Try the following steps:

    1. Run the app on a device
    2. Press the home button once to go to the home screen
    3. Press and hold the power button for 5 seconds until you see the power off slider
    4. Press and hold the home button for 5 seconds

    If you were running the app from Xcode you should see Message from debugger: Terminated due to signal 9

    0 讨论(0)
  • 2021-02-05 01:51

    You should be able to:

    • Tap the home button, to take you to the home screen
    • Tap the home button twice (use the keyboard shortcut in the simulator)
    • Touch and hold the icon at the bottom until it starts to wiggle
    • Tap the dash circle - to remove it from memory

    This gives you the app delegate methods of going into the background, etc. This is how it works in iOS 6 and below.

    0 讨论(0)
  • 2021-02-05 01:53

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

    0 讨论(0)
提交回复
热议问题