Testing a closed ios app

2019-06-23 14:51发布

问题:

I'm currently trying to handle different application states (closed, background or in a different tab of the app) however when I try to test how the app works when it is closed and receives a push notification(double click home and force close the app then reopen it) I'm not sure where I'm going wrong in the code. Since I'm reopening the app from the phone itself and not xcode I can't test to see which method isn't being reached because no output is available in the console. Is there any way to test a situation like this or simulate a force close event in xcode so that when i re run the app on the phone it also launches in xcode?

I appreciate any responses.
Cheers!

回答1:

If you force close app or stop (from xcode) then it close the connection with xcode. Then if you open it from phone then it will not make connection with xcode. You must run it from xcode. And there is no difference in opening app from phone or running from xcode. App's flow will be same in both case. So what you want to test that which methods get calls and in which sequence that you can check by rerunning the project.

Update:

  • Select the Scheme on the toolbar (just left beside from your device or simulator list)

  • Choose Edit Scheme

  • Select Run in the left panel

  • For the Launch option, select Wait for executable to be launched

Refer this link for more details



回答2:

Since I'm reopening the app from the phone itself and not xcode I can't test to see which method isn't being reached because no output is available in the console.

In Xcode, hold down the Option key and choose Product->Run..., and then edit the Run scheme to use the "Wait for executable to be launched" option. You should then be able to choose Run in Xcode, and then open your app by some other means, such as responding to a notification, and Xcode will still connect and let you debug.



回答3:

To debug the process after restarting the app again, attach the Xcode debug console to the running process.

In Xcode do:

Debug > Attach to process > [select your process]