APN BadDeviceToken iff running dev version
Asked Answered
D

2

15

The problem

I'm not receiving Push Notifications to my app when I'm working on it,
and the APN server returns "BadDeviceToken".

The situation

I've got to be missing something simple here, this is the situation :

  1. When I send a Push Notification to my app downloaded from the App Store it works

  2. When I send a Push Notification from the same server, to the same version (*) of my app but built off Xcode, the APN server returns a status: '400' fail with the failed[0].response.reason: 'BadDeviceToken'

(*) I say the same version, the code is the same and the plugins should be the same, but I have changed Cordova iOS version down to 3.x, from 4.x.

The tech

I'm using the newer method of Push Notifications where on the server I just have a .p8 APNs Auth Key on the server.
The server is node code using the node-apn plugin.
The client app is Cordova, using the Telerik Push Plugin.

What I've tried

  • I've tried creating a new APNs Auth Key and uploading that to the server; that still works on the App Store version of the app, and APN still returns "BadDeviceToken" when sending to my locally built version of the app.

  • I've tried setting production: false on the server config for node-apn before sending the push to my locally built app; I still get the "BadDeviceToken" error.

  • Doing an extra hexadecimal encode to the token as per this question; result is that it still says "BadDeviceToken", though in that case it would actually be true.

  • Bumping the cordova-ios version back up to 4.3.1; still getting "BadDeviceToken".

  • Double checking that the "Push Notifications" Capability is on when building

  • Doing a Release build rather than a Debug build, as suggested here, and described here

The question(s)

Why is the APN server saying BadDeviceToken when that is obviously not true?
And, how can I fix it?

Diaconicum answered 26/5, 2017 at 5:42 Comment(0)
D
13

Deleting the app and reinstalling it (ie. re-running it from Xcode) gave a new token and the new token worked without complaint.

Diaconicum answered 1/6, 2017 at 0:40 Comment(2)
My first ever bounty ... 50 reputation ... and the answer was to do a reinstall. :(Diaconicum
the struggle is real xDHerring
H
6

In addition to @kris's answer:

  • You could've probably gone solved it as well by running the app through xCode, that will generate a development build, and will need to use the APNS development gateway with a development certificate, not the production certificate.
  • Or if you are installing directly to your phone from Xcode, then you have to use Development security profile and make sure you are sending the notification from server side to iOS devlopment sand box. If you are using TestFlight/AppStore you need to use Production profile and make sure you are sending the notification to iOS production sandbox.

The SOLUTION however was found by the one that made the question itself, stating:

  • For some reason the Xcode project did´t use the right provision profile and the solution would be rather to re-install the app.

Further I'd like to explain what APNS_BAD_DEVICE_TOKEN is:

  • The specified device token was bad. Verify that you specified a valid token and that your Security Profile's type (development/production) matches your push certificate's type.
Herring answered 4/6, 2017 at 15:1 Comment(2)
I may have similar confusion. I am now testing in release mode and all APNS notifications (via AWS SNS) are failing. Can I run in release mode, with my test devices connected to my mac and using the Run button in xcode to launch my app, and send notifications using my production profile on AWS?Kado
this answer helped my situation. I wasn't getting push notifications after pushing an archive build via Test Flight (for our QA environment). Turns out, when pushing my server side code, I had to use "production: true", in my configurations for QA because the generated tokens must be different between a archive ipa vs pushing via Xcode to a device. hth.Morgun

© 2022 - 2024 — McMap. All rights reserved.