Menu

APNs BadDeviceToken (400): Causes and Fix, Including Sandbox vs Production
📰

APNs BadDeviceToken (400): Causes and Fix, Including Sandbox vs Production

DEV Community: ios·Notify sphere·2 days ago
#9ngr24XZ
#devtoios#devto#dev#token#apns
Reading 0:00
15s threshold

Your iOS push fails with 400 and "reason": "BadDeviceToken" . Before you delete that token, check one thing: is it going to the right APNs environment? Most of the time it's a sandbox token sent to production, or the other way round.

What the error looks like

APNs replies with HTTP 400 and a JSON body with the reason:

HTTP / 2 400 apns - id : 5E3F 9C1A - 7B2D - 4C 8E-9A 61 - 2F 0B 3D 4E5A 6C

{ "reason" : "BadDeviceToken" }

Enter fullscreen mode

Exit fullscreen mode

Apple's description is simply that the device token is invalid. The response doesn't tell you why, so check the likely causes in order.

Cause 1: sandbox and production are mixed up

APNs has two environments, and a device token only works in the one it came from:

# Development builds (run from Xcode with a development profile) https://api.sandbox.push.apple.com/3/device/<device-token>

# TestFlight, Ad Hoc and App Store builds https://api.push.apple.com/3/device/<device-token>

Enter fullscreen mode

Exit fullscreen mode

A build run from…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.