9

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!

Tyler Pierog
  • 527
  • 5
  • 15
  • Follow these instructions to set up and intercept your push notifications:http://stackoverflow.com/a/24899303/1894067 and you will solve any type of issue about it – Alessandro Ornano Jun 06 '16 at 13:35

3 Answers3

22

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

enter image description here

Refer this link for more details

Community
  • 1
  • 1
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • My only issue with that is that when I close the app via xcode it doesnt force close the app on the phone but just puts it in the background (push notification works in that state) however if the user force closes the app on the phone it wont work – Tyler Pierog Jun 06 '16 at 13:42
8

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.

Caleb
  • 124,013
  • 19
  • 183
  • 272
4

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]

Hodson
  • 3,438
  • 1
  • 23
  • 51
  • Which is my process? –  Feb 03 '19 at 01:46
  • 1
    The process should have the name of your app. It usually shows at the top of the list under the headline "Likely Targets" – Hodson Feb 04 '19 at 10:27
  • Yeah I found it now, but it only shows up while the app is running, so how actually does one test how an app behaves after closing it, without manually building it from Xcode again (which opens it and kinda kills the whole point)? –  Feb 06 '19 at 20:01