Expo Push Notification Receipt states "BadDeviceToken"

Please provide the following:

  1. SDK Version: 34.0.3
  2. Platforms(Android/iOS/web/all): iOS

High-Level Problem
After upgrading to IOS 13 and installing the latest version of our app from the app store, we stopped receiving push notifications.

Details
Our app is generating push notification device tokens by calling Notifications.getExpoPushTokenAsync() which we then store in our database for later reference.

We generate push notifications by POSTing to https://exp.host/--/api/v2/push/send, and have been doing so successfully for several months.

This problem occurs when using the Expo Push Notification Tool as well.

When I retrieve the push notification receipt, it contains the following:
{"status":"error","message":"The Apple Push Notification service failed to send the notification (reason: BadDeviceToken, status code: 400). Read Apple's docs about \"Communicating with APNs\" to learn what this error means.","details":{"apns":{"reason":"BadDeviceToken","statusCode":400},"sentAt":1569011007},"__debug":{}}}}

When loading the app from the Expo CLI, we receive push notifications just fine.

This could be related to a breaking change in iOS 13 explained here: iOS 13 and Xcode 11 Changes That Affect Push Notifications. SDK 35 has a fix, so upgrading and rebuilding your app binary should address the issue.

It looks like some problem with iOS 13. Not sure if just for the beta or the production build as well. I’m using 13.1 beta 4 and having the same problems. The notifications are being received in my iPad using iOS 11.

I created a topic a few minutes before you reporting the same problem:

It’s looking like it is not just the beta. There was a breaking change in iOS 13 that affects all existing apps. The fix is to upgrade to SDK 35, rebuild your app binary, and resubmit to the App Store. We are also looking into back-porting the fix to the SDK 34 builders, in which case you will need to rebuild your app binary and resubmit to the App Store but not upgrade your SDK version if you’re already on 34.

1 Like

Thanks ide, I will confirm your fix as soon as I can make and test this fix.

Writing again to confirm that ide’s instructions to upgrade to SDK 35 does fix this issue.

1 Like

Can confirm too, it’s working. Thanks, guys.

1 Like

@ide can you elaborate on a bit on the fix? Is this something in Expo’s RN fork or another component? I’m wondering what we need to update in ExpoKit apps in order to fix this. Thanks!

This is the commit with the fix: [iOS] make apnsTokenString resistant to breaking change of iOS13 (#5398) · expo/expo@af47fe5 · GitHub

Thanks for the info! Heads up for anyone else dealing with this that we ended up copying in the latest version of the file (expo/NSData+EXRemoteNotifications.m at master · expo/expo · GitHub), as it also incorporated making the token lowercase, which was necessary for our older APNS server-side library.

For anyone on ExpoKit not ready to upgrade to SDK 35, but wanting to make patching of this file more automatic in a patch-package-style solution, what we ended up doing was putting the updated code in a .fixed file in our project, and then copying it over the file in the ExpoKit cocoapod using a shell command in the post_install do |installer| block of Podfile:

puts "Copy NSData_EXRemoteNotifications.m file with iOS 13 APNS token fix"
    %x( chmod u+w Pods/ExpoKit/ios/Exponent/Kernel/Services/Notifications/NSData+EXRemoteNotifications.m )
    %x( cp NSData+EXRemoteNotifications.m.fixed Pods/ExpoKit/ios/Exponent/Kernel/Services/Notifications/NSData+EXRemoteNotifications.m )

That way, this fix will always get restored when someone restores our project’s cocoapods.

Im running on SDK 34, builder already patched ? im getting in troubles with notifications on iOS 13, thanks !!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.