How to debug app when launch by push notification in Xcode
Solution 1
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!
Solution 2
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
Solution 3
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)
As soon as the app is launched or if it is already launched, the debugger will be plugged. Really helpful in two cases :
- notification/location debug
- you didn't launch the app through Xcode but you have a strange bug you want to understand
dk-obl
Updated on June 19, 2022Comments
-
dk-obl almost 2 years
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.
-
Kirk Hammett over 7 yearsDidn't work for me on xcode 8.2.1. When I run the app manually, debugger simply shows empty output.
-
Jirson Tavera almost 7 years@KirkHammett could you say me what you did for xcode 8.2.1? it show me empty :/
-
Kirk Hammett almost 7 years@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.
-
auspicious99 over 6 years@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?
-
mfaani over 5 yearsI 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?
-
arturdev over 5 years@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.
-
mfaani over 5 yearsI 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! -
arturdev over 5 years@Honey If after hitting run button didFinishLaunching is getting called, then you haven't set "Waiting for the app to launched manually" checkbox
-
mfaani over 5 years@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 and other answers. To me it's poor choice of words from Apple. -
mfaani over 5 yearsFWIW in my Xcode capabilities I have enabled 'Background Fetch'.
-
Mizmor about 5 yearsStill Relevant For XCode 10!
-
Roman Samoilenko about 4 yearsIn this mode the debugger lags quite a bit. Very hard to debug unfortunately.
-
ArpitM about 3 yearsIt 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.