如何模拟在后台被杀的应用? [英] How can I simulate app being killed in background?

查看:125
本文介绍了如何模拟在后台被杀的应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证我的应用程序(App1)在启动另一个应用程序(App2)后被系统关闭时的行为是否正常。有没有办法模拟或强制这种行为?

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?

在App2运行时,告诉模拟器模拟内存警告,直到App1被带回到前景。从调试器中杀死App1会模拟相同的应用程序事件序列吗?

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?

编辑:我的应用程序在启动第二个应用程序来处理文件时放在后台。第二个应用程序然后重新启动我的应用程序,我正在尝试验证我的应用程序在第二个应用程序执行时关闭系统时表现正常。

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.

推荐答案

是的,如果您的应用已经在后台。在后台被系统杀死的应用程序在没有警告的情况下终止 - 没有调用应用程序委托方法,也没有进行状态更改 - 这正是当应用程序在后台执行调试器停止时发生的情况。 (这预示着您已经通过单击模拟器上的主页按钮或Cmd-Shift-H将您的应用程序置于后台)

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)

(正如@Inafziger所说,您也可以通过使用模拟器的界面强制退出正在运行的应用程序来获得相同的效果。)

(As @Inafziger notes, you can also get the same effect by using the simulator's interface to force quit the running app.)

这篇关于如何模拟在后台被杀的应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆