APNs push configuration mismatch between local development and production distribution
0 reputation · 12 Jan 2025, 17:46 UTC
0 reputation · 12 Jan 2025, 17:46 UTC
APNs maintains separate sandbox and production environments with distinct endpoints and token namespaces, and supports both certificate-based per-App ID authentication and token-based authentication using a team key.
A design question arises when an app is built for local development versus App Store or production TestFlight distribution. Device tokens are environment specific, and push capability must be enabled in the App ID and reflected in the provisioning profile used for signing.
The decision point is which combination of environment endpoint, authentication method, and provisioning profile entitlements is valid for each build configuration, and how to ensure consistency between Xcode schemes and server-side sender configuration.
What determines the correct APNs endpoint and credential pairing for a given distribution profile? Can a single token-based team key be used for both sandbox and production without separate configuration? How does the Push Notifications entitlement in the production provisioning profile affect token registration compared with a development profile?
The APNs endpoint and credential that must be used are dictated by the aps-environment entitlement embedded in the provisioning profile that signs the app. A development profile carries aps-environment = development and requires the sandbox endpoint (api.sandbox.push.apple.com) together with a development certificate or the APNs key configured for the sandbox. A distribution (Ad Hoc, TestFlight, App Store) profile carries aps-environment = production and must use the production endpoint (api.push.apple.com) with a distribution certificate or the same APNs key but uploaded for the production environment.
If the entitlement says development while your push server targets api.push.apple.com (or uses a production certificate), APNs will reject the device token as invalid for that environment, resulting in silent drops or an InvalidToken error. Conversely, a production‑signed app talking to the sandbox endpoint will also be rejected because the token namespace does not match.
aps-environment entitlement.registerForRemoteNotifications will be a sandbox token when the entitlement is development and a production token when it is production.codesign --display --entitlements - /Path/to/YourApp.app Look for <key>aps-environment</key><string>production</string>.api.push.apple.com (not the sandbox host) and that the credential uploaded matches the production environment (distribution certificate or the APNs key marked for production).200 response confirms correct pairing.To verify that the mismatch is indeed the cause, please share the exact error code or response you receive from APNs when attempting a production push (e.g., InvalidToken, BadDeviceToken, or HTTP status). This will confirm whether the environment/credential pairing is the issue.
Use comments to ask for clarification. Post a solution as an answer.
29,275 reputation · 12 Jan 2025, 21:59 UTC
To resolve mismatches between local development and production distribution, it is helpful to verify the actual entitlement embedded in the compiled binary rather than relying solely on the Xcode project settings. This ensures the provisioning profile was applied correctly during the build process.
You can inspect the aps-environment value of a compiled .app or .ipa using the codesign utility in the macOS terminal:
codesign -d --entitlements :~/Path/To/YourApp.app > entitlements.plist
Open the resulting entitlements.plist to confirm if the value is set to development or production. If the value does not match your server's target gateway (api.sandbox.push.apple.com vs api.push.apple.com), APNs will return a BadDeviceToken or InvalidToken error, regardless of whether you are using a shared .p8 auth key.