NativeScript / push-plugin

Contains the source code for the Push Plugin.
Apache License 2.0
123 stars 48 forks source link

Apns notification error: 'InvalidToken' #240

Open dpdragnev opened 5 years ago

dpdragnev commented 5 years ago

We are experiencing an issue with sending notifications to our test iOS device. Everything works well on Android. Here is our environment:

nodejs: 8.9.4 npm: 5.8.0 tns-ios: 4.1.0 push-plugin: 1.0.4 tns: 4.1.2

The certificates, the provisioning profile, and the p12 files were generated on the same machine (iMac).
The correct certificate and provisioning profile are set up in Sidekick. We are testing it via pushtry.com as well as locally via our API.

Here is how we generate the token:


    //iOS
    let iosSettings = {
      badge: true,
      sound: false,
      alert: true,
      clearBadge: false,
      interactiveSettings: {
        actions: [
          {
            identifier: "READ_IDENTIFIER",
            title: "Read",
            activationMode: "foreground",
            destructive: false,
            authenticationRequired: true
          },
          {
            identifier: "CANCEL_IDENTIFIER",
            title: "Cancel",
            activationMode: "foreground",
            destructive: true,
            authenticationRequired: true
          }
        ],
        categories: [
          {
            identifier: "READ_CATEGORY",
            actionsForDefaultContext: ["READ_IDENTIFIER", "CANCEL_IDENTIFIER"],
            actionsForMinimalContext: ["READ_IDENTIFIER", "CANCEL_IDENTIFIER"]
          }
        ]
      },
      notificationCallbackIOS: (message: any) => {
        //console.log('Push notification from iOS: ', message);
        //let response = JSON.parse(message);
      }
    };

    pushPlugin.register(
      iosSettings,
      (token: String) => {
        appSettings.setString(SettingsEnum.DEVICE_TOKEN.toString(), token.toString());

        pushPlugin.registerUserNotificationSettings(() => { }, err => { });
      },
      function (errorMessage: any) {
        console.log("Error from Apple notification: ", errorMessage);
      }
   );```

What are we missing?

Thank you.
tbozhikov commented 5 years ago

Hi @dpdragnev You could check online for such errors (like this thread) as it is more like a setup issue rather than plugin issue.

dpdragnev commented 5 years ago

Hello @tbozhikov

I am using a Mac and I followed the instruction from this article to the letter.

The token is generated properly in the correct format and I can verify that the plugin successfully completes the call to registerUserNotificationSettings.

The notifications are enabled on the device and in XCode as well as in the app profile in developer.apple.com.

I am really running out of places to look at. Any suggestion would be greatly appreciated.

Thank you.

tbozhikov commented 5 years ago

Hi @dpdragnev If you are not using interactive push notifications in your project, you may try implementing the push functionality with the {N} Firebase plugin - not only because we are going to deprecate the push-plugin in the future, but also because the Firebase plugin promotes another way of sending/testing your push notifications (through the Firebase console for both Android and iOS). This may make difference in your setup and work with no errors. Let us know if you try this way and what is the outcome.

dpdragnev commented 5 years ago

Thank you @tbozhikov

I will look into it and will report back.