Debug Notification Extensions
Asked Answered
H

10

42

I'm building a set of Notification Extensions (Service/Content). I'm unable to connect to Xcode debugger or even log out to the device log or console.

Is there any way to see any kind of output?

Heartland answered 1/7, 2016 at 8:2 Comment(0)
I
63

Change the target to run the extension

Change Target

then select run and choose your app from the 'Choose an app to run:' window.

enter image description here

Intromission answered 18/8, 2016 at 21:32 Comment(2)
@brenden : I am getting "Program ended with exit code: 0"Tarttan
This also worked for me with a FileProvider extension selecting the Files app, though I had to actually enter my file provider in Files before debugging began.Ave
T
37

I have tried as per brendan's Answer but is not working for me at all!

I am getting below error in console

Program ended with exit code: 0

Then after searching on google i have checked this answer. however this also not worked for me for while!

Then i have tried same steps again as given in answer, After stopping my current running app. then follow same steps.For clarity i am writing this steps as below:

After running the app that contains the extension,

1) Set your breakpoint in the extension
2) Select Debug / Attach to Process by PID or name
3) Enter the name of the extension target
4) Trigger the push notification

Before step 2 make sure to stop your current running app.

Tarttan answered 14/11, 2017 at 5:42 Comment(4)
in my case getting this Program ended with exit code: 0 2) Select Debug / Attach to Process by PID or name : not clear this step can you please explain ?Wally
@Wally Click on Debug from Top Menu -> Then Attach to process then follow step 2,3,4Tarttan
The funny thing is in my case, I tried this approach first (attach by name) and I just got an error saying my user did not have permission to attach to my extension process. The choosing the target to run the extension did work... so if people have issues, try both.Ave
Worked a few times, after which I'm getting 'Terminated due to signal 9'...Klansman
I
15

This worked for me to stop at breakpoints in the extension and see the extension log:

  1. Choose the notification extension scheme, not the main app scheme
  2. Run the app and select the main app from the list Choose an app to run
  3. Stop the app in Xcode and terminate it manually on the device; not terminating it manually results in Message from debugger: Terminated due to signal 9 after step 6. [Update: Terminating the app manually on the device doesn't seem to be necessary, try either way if it doesn't work.]
  4. Select Menu Debug > Attach to Process by PID or Name
  5. Enter the correct extension name, not the main app name
  6. Send the push notification
Ianthe answered 3/6, 2018 at 22:40 Comment(4)
Hi, Manuel, I've followed your guide, but I still have this Message from debugger: Terminated due to signal 9 error. And I'm sure I've manually terminated my main app. Do you have any idea about this? Could this be affected by background refresh? the main app process is still alive?Transudate
@Transudate I don't see any reason why it would be affected by background refresh. At this point I would suggest you play around a bit with the order of the steps in my answer. It seems to work for everyone a bit differently, maybe no-one has really figured out the correct steps that work for everyone yet.Ianthe
@Transudate See my update for step 3: try not to terminate the app manually on the device, it just worked for me, maybe it works for you.Ianthe
Finally I find that it’s some thing wrong with my project configuration. After I switch to another target, my project has three targets with different configuration, it works.Transudate
N
9

In my case all methods above had some mistakes. Main point, that you need to send push one time, then connect through debugger, then send push to debug. So, full list:

  1. Launch app (not extension).

  2. Stop app from XCode.

  3. Send one push.

  4. Connect via "Attach to Process by PID or Name..." to your extension process.

  5. Send another push.

Nourishment answered 6/12, 2018 at 7:44 Comment(0)
G
8

Notification service extension (NSE) is not actually a part of your app but an extension that said it has a different process id (PID) from your app. You can have XCode listen to every process on your phone by going to the “Debug” tab, scroll down to “Attach to Process” and look to see if your NSE is listed under “Likely Targets”. If it's not there than try to sand another push notification to your device and attach to it when it appears.

enter image description here

Now in debug navigator you can see the NES process and you can successfully debug it.

enter image description here

Guyot answered 27/11, 2018 at 11:7 Comment(0)
A
7

If you have tried all the above solutions and still scratching your head and wondering why break point point is not being called. Then try checking the deployment target of your extension it should be less or equal to your device OS.

For me, the deployment target was higher than the device OS.

Abraham answered 12/12, 2019 at 11:17 Comment(1)
Thanks! This was the issue for me after spending couple hours trying to make it work.Noelianoell
R
3

In my case (Xcode 11.1) debug starts after this steps:

  1. run notification extension target with main app
  2. switch app to background
  3. lock the phone !
  4. send push to device
Repulse answered 13/11, 2019 at 6:18 Comment(0)
F
2

I followed solutions mentioned here but nothing helped. I found out that problem is when payload of notification does not contain flag to enable content to be mutated. Notification without this flag are not handled by NotificationExtension at all. After I added "mutable-content": 1 to the payload and followed answers here I was able to alter content of push notification and to debug code in NotificationExtension.

{
  "aps": {
    "mutable-content": 1,
    "alert": {
      "title": "Push Title",
      "body": "Push payload body"
    }
  },
  "data": "what ever you need to be in userInfo"
}
Foust answered 9/11, 2022 at 15:40 Comment(0)
L
1

The only way that worked for me was to see logs. I use xcode 10.1. The logs were available from Window -> Devices and Simulators -> Choose your device -> click on 'Open Console'. This way i could see logs from extensions as well.

Leaguer answered 16/5, 2019 at 22:29 Comment(1)
This, plus I had to use NSLog() rather than print()Gonsalves
T
0

Not sure if this will be helpful, but we have multiple builds of the same app (alpha, beta, etc). Kept getting a "don't have permissions to attach" error when trying to debug. Opening up the processes list, I noticed that there were 2 processes named notification-extension so xcode must have been defaulting to the one of the other build. By manually selecting the right one, or deleting the other builds from my phone things started working again.

Tyratyrannical answered 8/5, 2018 at 23:38 Comment(1)
Hi, Josh. Could you please tell me how to Opening up the processes list, I just don't know how to monitor processes running on my phone.Transudate

© 2022 - 2025 — McMap. All rights reserved.