iOS: Invalid token error for push notifications
Handling gateway errors when testing iOS push
An invalid token error may be given when testing notifications for a development/enterprise build of an iOS App. The most likely cause is that the notification was sent via the wrong gateway due to a misconfiguration, but may also be caused by having a mismatch between the bundle ID of the certificate and the bundle ID of the app.
If you have done a development build the problem will be that the app has a sandbox token from Apple, but you are not sending via the APNS sandbox gateway. Apple has two notification gateways: one for sending to development builds (sandbox) and the other for sending to production builds. To test with a development build, you will need to enable sandbox mode when initialising in the App Delegate:
and then select the sandbox gateway in Xtremepush when sending the message. If you have done an ad-hoc or enterprise production build so you can test with the production gateway, the issue will be that you have set sandbox mode and not removed it.
If you test using development builds then you should turn on Sandbox Mode when testing, as Apple uses a different gateway for builds compiled with a development mobile provisioning profile. If you only do enterprise builds you won't need this. Set sandbox mode in a statement that will only run for development builds as it should not be turned on in production.
You can also turn on debug logs for the SDK in this way:
[XPush registerForRemoteNotificationTypes:types]; // Only runs for development builds sets push to sandbox mode and turns on debug logs #if DEBUG [XPush setSandboxModeEnabled:YES]; [XPush setShouldShowDebugLogs:YES]; #endif [XPush applicationDidFinishLaunchingWithOptions:launchOptions];
Bundle ID mismatch
If the gateway setting looks OK then another likely cause is uploading a certificate that targets a bundle ID that is different from that of the app. For example, your app's bundle ID is
com.example.app1 but the certificate you have uploaded targets
Updated almost 2 years ago