Unknown APNs ERROR: BadEnvironmentKeyInToken when sending Push To Talk notifications

We’re sending PTT notifications from our server and are receiving HTTP 403 from APNs for certain phones with the reason field BadEnvironmentKeyInToken. I can’t find this reason documented in Apple’s public error list. I’d like to confirm what this error specifically means and how to resolve it. Any guidance or clarification would be greatly appreciated. Thank you. Here is the document I was referring to. https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html

Crazy that there's an error that is not documented. Anyhow, I think I got this because I was using a p8-file that was for production only but a device token generated for development environment. Fix: re-generate a p8-file for both development and production. Update APNS_KEY_PATH and APNS_KEY_ID accordingly.

Hi, I'm experiencing the exact same issue with BadEnvironmentKeyInToken (HTTP 403) from APNs. In my case:

I'm using a P8 key (not certificate-based auth) The P8 key was recently created with APNs service enabled Everything works fine with sandbox/development environment (Debug builds via Xcode) The error only occurs with production environment (TestFlight builds) My provisioning profile correctly shows aps-environment: production The device token is valid for production (confirmed by the profile)

The strange part is:

Sandbox server (api.sandbox.push.apple.com): Returns BadDeviceToken (expected, since token is for production) Production server (api.push.apple.com): Returns BadEnvironmentKeyInToken (HTTP 403)

My JWT generation looks correct (same key works for sandbox), Team ID, Key ID, and Bundle ID are all verified to be correct. Did you ever find a solution to this issue?

Unknown APNs ERROR: BadEnvironmentKeyInToken when sending Push To Talk notifications
 
 
Q