How to debug app when launch by push notification in Xcode

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


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

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 not be 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