Why don't I receive iOS Push Notifications with a debug build connected to Xcode debugger?
Asked Answered
S

2

10

When I test the app using a TestFlight version built by the CI machine, the device receives push notifications.

But when I rebuild the app under Xcode locally with the debugger connected, the device doesn't receive any push notifications.

To validate things further I again tested locally with a push notifications tester, and the device indeed received a push notification.

So the code isn't omitted due to it being a #DEBUG build as the grant and registrations pass.

What is my local build possibly missing?

Semiporcelain answered 12/3, 2019 at 23:56 Comment(1)
Perhaps you can tell us which remote notification delegate methods that you’ve implemented. When you’re attached to the debugger, the lifecycle of the app changes (i.e. it continues to run even if you’ve transitioned away from the app). FWIW, I like to monitor this sort of stuff using OSLog, which I can remotely monitor from my macOS console, so that I’m not letting the fact that it’s connected to the debugger affect app lifecycle.Scrod
S
2

The solution ended up being that our server with the Houston gem needed to configure its APNS support to be in development mode, and not in production mode. 👍

Semiporcelain answered 15/3, 2019 at 23:17 Comment(0)
H
4

When you build your app in debug locally your app will generate a unique device token that doesn't receive production push notifications. When you build your app with a distribution provisioning profile it generates a different device token that does work on production.

Apple will reject a development device token unless you are specifically requesting a push notification using your APNS Sandbox certificate.

So if you haven't already you'll have to go through the certificate creation process all over again but this time for a sandbox certificate and use that one instead.

Hurlbut answered 13/3, 2019 at 0:17 Comment(5)
Even though my certificate is under Production, the Apple Push Notification service SSL (Sandbox & Production) lists Sandbox. If I were to grab the release distrib. version of the token string, could I use it in place of my dev. token to fake it?Semiporcelain
Device tokens can change pretty frequently and they do this when the app is installed, this is why you have to re-register the device token on startup every time. So there wouldn't be such a thing as the release version of the token, just the token that's generated at that point in time. And the token has to match what's been registered with apple. So I don't see that as a possibility sorry. Out of curiosity are you using your own server to send the notifications or a third party platform?Hurlbut
I've got two devices, same app. XS is a TestFlight release build. 5S is connected through Xcode. 5S -> PN -> XS = success. XS -> PN -> 5S = fails. 5S never receives a PN. Our own server is assisting using this gem (github.com/nomad/houston).Semiporcelain
Houston provides a command line tool, have you tried sending a notification using that? apn push "token" -e development -c /path/to/apple_push_notification.pem -m "message" Try doing that with both the -e development and -e production flags. On your web server make sure you're setting the Houston client environment to Houston::Client.development with the corresponding sandbox certificate and device token as well.Hurlbut
What if I'm using the newer and recommended APNs Authentication Key instead?Billi
S
2

The solution ended up being that our server with the Houston gem needed to configure its APNS support to be in development mode, and not in production mode. 👍

Semiporcelain answered 15/3, 2019 at 23:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.