62

I am using Xcode 5. I am working with push notifications in iOS. I am getting satisfying results for background mode and foreground mode that can be debugged easily on an iOS device.

But problem is when app is in closed state and launched by push notification tap but I don't know how to debug in this situation. I know the solution for Xcode 4 but not for Xcode 5.

So is there any solution for Xcode 5 and debugging the app when launching it by push notifications? Provide steps to debug in this situation.

Cœur
  • 32,421
  • 21
  • 173
  • 232
dk-obl
  • 671
  • 1
  • 5
  • 8

3 Answers3

152

Edit your project scheme and set "Launch" to "Wait for *.app to be launched manually". Then Run the project or hit "cmd+R". The app will be not launched automatically, but the debugger will attach to the process as soon as the app launches. So send your test push notification, and launch the app from the push.
Here you go!

enter image description here

arturdev
  • 10,228
  • 2
  • 34
  • 62
  • 8
    Didn't work for me on xcode 8.2.1. When I run the app manually, debugger simply shows empty output. – Kirk Hammett Jan 17 '17 at 20:14
  • @KirkHammett could you say me what you did for xcode 8.2.1? it show me empty :/ – Jirson Tavera Jul 17 '17 at 21:09
  • 1
    @JirsonTavera I've managed to find the problem in my code using breakpoints and my iPhone – unfortunately way of debugging described above didn't work for me. – Kirk Hammett Jul 19 '17 at 09:13
  • @KirkHammett I had the same problem of debugger showing empty output, when launching the app through a push notification, after "wait for *.app to be launched manually". I can set breakpoints, but can't test the scenario of starting the app through push notification. Any ideas? – auspicious99 Sep 19 '17 at 03:41
  • 1
    I want to test a different scenario. I want to force-quit the app. And then launch it from a local notification. But even after I enable this and tap on a local notification none of my breakpoints are hit. Is this suppose to work for this scenario? – Honey Sep 12 '18 at 14:13
  • @Honey Yes, but after force killing, you should hit Run button again with "Waiting for the app to launched manually" enabled, as I described in my answer. – arturdev Sep 12 '18 at 14:50
  • I don't get you. If am to hit run again then it would launch the app again! It would no longer be in a terminated state. Each time I hit Run button it triggers the `didFinishLaunching` **while** it actually doesn't launch the app. I don't think background App Refresh can launch an app from a terminated state, hence it has to launch the app! Your solution works for when app is either in background/suspended state. It doesn't correctly reproduce a user-termination state because it launches the app or as you mentioned debugging gets started! – Honey Sep 12 '18 at 15:32
  • @Honey If after hitting run button didFinishLaunching is getting called, then you haven't set "Waiting for the app to launched manually" checkbox – arturdev Sep 12 '18 at 15:39
  • @arturdev to be honest I had the same exact thought. I mean in it's wording **Waiting for the app to launched**. I totally get. But yes I have it enabled. Can you do me a favor? Just try it for yourself and see if your didFinishLaunching does get call or not? Proof that I've enabled is that the app doesn't not get launched into the SCREEN, still `didFinishLaunching` is called. For more on why it needs to launch the app I recommend you to see [here](https://stackoverflow.com/a/44929057/5175709) and other answers. To me it's poor choice of words from Apple. – Honey Sep 12 '18 at 15:43
  • FWIW in my Xcode capabilities I have enabled 'Background Fetch'. – Honey Sep 12 '18 at 15:47
  • Still Relevant For XCode 10! – Mizmor Mar 18 '19 at 20:59
  • In this mode the debugger lags quite a bit. Very hard to debug unfortunately. – Roman Samoilenko Mar 19 '20 at 07:05
  • It appears to work in Xcode 12.4, but it's a bit goofy where the app doesn't update or the log doesn't appear. However, it's somethiing. – Mr Rogers Apr 13 '21 at 23:10
6

it takes few seconds:

1- go to edit schema

2- select run section from left list

3- then in info tab goto part launch options

4- select option: wait for executable to be launched

5- then close the window

6- run the app : the app will build but not launched because it's waiting for you to launch the app manually

7- at this time send your notification to your device

8- tap on the notification and your app will launched and the debugger goes to breakpoints you attached in lines of code

NoodleOfDeath
  • 13,338
  • 21
  • 69
  • 100
jamal zare
  • 563
  • 6
  • 8
2

You can also connect to the app in debug mode using the debug menu of Xcode : Debug > Attach to process by PID or name (start typing the name of your target and Xcode will autocomplete for you)

Debug option

As soon as the app is launched or if it is already launched, the debugger will be plugged. Really helpful in two cases :

  1. notification/location debug
  2. you didn't launch the app through Xcode but you have a strange bug you want to understand
CedricSoubrie
  • 6,467
  • 2
  • 34
  • 44