I am testing sending notifications on iOS and they are failing with error invalid token what's wrong?

This can happen when testing a development/enterprise build of the iOS App to test if notifications are working. The most likely cause is that the notification was sent via the wrong gateway due to a misconfiguration (1 below). It may also be caused by having a mismatch between the bundle id of cert and the bundle id of the app (2 below).
1) If you have done a development build the problem will be that the app has gotten a sandbox token from apple but you are not sending via the APNS sandbox gateway. Apple have two notification gateways one for sending to development builds (sandbox) and the other for sending to production builds. To test with a dev build you will need to enable sandbox mode when initialising in the App Delegate
Obj-C:  [XPush setSandboxModeEnabled:YES];
Swift:   XPush.setSandboxModeEnabled(true)
and then select the sandbox gateway in the platform section of campaign creation 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.

NBIf 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];
[XPush applicationDidFinishLaunchingWithOptions:launchOptions];
2) If above looks OK then another likely cause is uploading a cert that targets a bundle id that is different from that of the app for example:
  • Your Apps bundle ID is com.example.app1
  • But the cert you have uploaded targets com.example.app2 or com.example.app1.somethingelse
Have more questions? Submit a request


Please sign in to leave a comment.