1

I'm using phonegap-plugin-push in an ionic 3 app.

However lately as more phones get updated to iOS 13 and above the registration of devices wont work anymore.

Device makes a call to an api on our side that in turn registeres phone with azure push hub.

This is how i have set up the registration process ionic.

   const options: PushOptions = {
      android: {
        senderID: "58846546653626",
        icon: 'pushicon',
        iconColor: '#7BC3AD' //light blue green thingy
      },
      ios: {
        alert: "true",
        badge: "true",
        sound: "true"
      }

    };

    this.pushObject = this.push.init(options);

    this.pushObject.on('registration').subscribe(data => {
      this.pushRegister(data);
    });

  pushRegister(data: any) {
    // Get the native platform of the device.
    let platform: any = device.platform;
    // Get the handle returned during registration.
    let handle: any = data.registrationId;
    // Set the device-specific message template.
    let infoToRegister: any = {
      "Platform": (platform == 'android' || platform == 'Android') ? 'gcm' : 'apns',
      "DeviceToken": handle,
      "Tags": [] //set serverside based on authorization
    }
    let url = (globalVars.serverurl+ 'api/Register');

    let options = this.dataService.getRequestOptions();

    let body: string = JSON.stringify(infoToRegister);

    this.httpClient.post(url, body, options).subscribe(successResponse => {
      console.log(successResponse);
    }, errorResponse => {
      console.log(errorResponse);
    });
  }

This all works well with phones running iOS below 13.

However with iOS 13 registrationId looks totally different and the api method that registered to azure push hub throws an error: One or more characters in device token is not a hexadecimal digit.

Example of posted data from iOS 13 that fails:

{"Platform":"apns","DeviceToken":"{length=32,bytes=0xc0d97379b07611f8e4e7529e3ee02e1d...d0a4e98468524d88}","Tags":[]}

Is there any way to get the correct token ? as seen above the bytes is also truncated so i guess i cant register with that either.

nios
  • 130
  • 12
  • I did update phone from iOS 13.1.2 => 13.2.3 and now registration works again. However i'm not sure this is a solution to the problem. It might be possible to solve it some other way. – nios Dec 05 '19 at 11:40

2 Answers2

1

Problem

This is because of these 4 broken changes: https://onesignal.com/blog/ios-13-introduces-4-breaking-changes-to-notifications/

Solution - 1

It has well explained here: Does iOS 13 has new way of getting device notification token?

Solution - 2

If you are using Objective-C or Swift 3x then follow this link: Get device token for push notification

Solution - 3

If you are using Ionic - OneSignal, please follow this link: Ionic - OneSignal doesn't work on iOS 13.x

Solution - 4

If you are using phone-gap plugin to resolve this issue while builing Mobile App using Ionic Cordova then please follow this link: https://github.com/phonegap/phonegap-plugin-push/issues/2819

Ritesh Aryal
  • 825
  • 9
  • 13
0

If anyone comes across this question and is not using Ionic, but it using plain Cordova, the solution is to update your phonegap-plugin-push plugin to version 2.3.0 or higher (the pull request containing the fix is here: https://github.com/phonegap/phonegap-plugin-push/pull/2808 ).

You can verify that you have the correct version of the plugin installed by running the command: cordova plugins

For good measure, make sure that you run cordova platform remove ios and cordova platform add ios after updating the push notification plugin to ensure that the updated plugin is properly built into the compiled app. There are a number of ways that an old version of the plugin can persist in the compiled app.

Elliot B.
  • 17,060
  • 10
  • 80
  • 101
  • I did end up upgrading the base cordova packages in my project. which of course lead to upgrading just about every other package as well. But first after doing this could i update to the newer phonegap-plugin-push. "cordova-android": "^9.0.0", "cordova-ios": "^6.0.0", "phonegap-plugin-push": "^2.3.0", – nios Mar 19 '21 at 06:59