How can I simulate app being killed in background?

后端 未结 4 1091
小蘑菇
小蘑菇 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".

提交回复
热议问题