phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

BadDeviceToken (APNS) when I download the app from Testflight (iOS) #2352

Open Juliocbr opened 6 years ago

Juliocbr commented 6 years ago

Actual Behaviour

Plugin generates device token correctly when I run the app with "ionic cordova run ios" command, but when I upload app to testflight and download the app, the generated device token is invalid for APNS, the message that I received from APNS is "BadDeviceToken".

I have configured the development and production certificates for push notifications in apple developer webpage for the app.

Cordova CLI version and cordova platform version

ionic (Ionic CLI) : 3.20.0 cordova (Cordova CLI) : 7.1.0 Xcode 9.3 cordova ios: 4.5.4

Plugin version

phonegap-plugin-push 2.2.2

For example this token is invalid:

bd4b61ffa8c7d77be841dc50169eca94cc633812833917a520456df9e1a5d779

This is my code:

initPushNotification() {
        if (!this.platform.is('cordova')) {
            console.warn('Push notifications not initialized. Cordova is not available - Run in physical device');
            return;
        }

        const options: PushOptions = {
            android: {
                senderID: 'xxxxxxxxxxxx'
            },
            ios: {
                alert: 'true',
                badge: false,
                sound: 'true'
            },
            windows: {}
        };

        const pushObject: PushObject = this.push.init(options);

        pushObject.on('registration').subscribe(data => {
          console.log("device token: " + data.registrationId);
          this.storage.set('deviceToken', data.registrationId);

          this.notifications.registerDevice(data.registrationId).subscribe(response => {
            console.info('registerDevice');
            // console.log(response);
          }, error => {
            console.error('error registerDevice');
            console.error(error);
          });
        });

        pushObject.on('notification').subscribe(data => {
          // console.log('message: ' + data.message);
          // console.log('count: ' + data.count);

          this.badge.set(Number(data.count));

          this.alertCtrl.create({
            buttons: ['Aceptar'],
            title: data.title || null,
            message: data.message
          }).present();
        });

        pushObject.on('error').subscribe((e) => {
          // console.log("ERROR PUSH!!!");
          console.error(e.message);
          console.error(JSON.stringify(e));
        });
    }
macdonst commented 6 years ago

@Juliocbr if you are using test flight you need to send to production APNS not development APNS.

HugoHeneault commented 6 years ago

@macdonst Do you think there could be a way to get the APNS-env value? 🤔 So the server could handle both dev & prod notifications depending on how the device got the app (from store/testflight or build locally)

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.