phonegap / phonegap-plugin-push

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

Callbacks (hasPermission, register) are not called on iOs 13 #2919

Open sebge2emasphere opened 4 years ago

sebge2emasphere commented 4 years ago

Expected Behaviour

The promise hasPermission must at some point answer something, but nothing happens.

Actual Behaviour

console.log('before permission');

try {
       this.push.hasPermission()
            .then((res: any) => {
                if (res.isEnabled) {
                    console.log('We have permission to send push notifications');
                } else {
                    console.log('We do not have permission to send push notifications');
                }
            })
            .catch(error => {
                console.error(error);
            })
            .finally(() => {
                console.log('has permission finally block');
            });
}
catch(e){
   console.log('error', e);
}

console.log('after permission');

This code works on Android, but on iOs the only output is 'before permission' and 'after permission'.

I also tried this (it works on Android):

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

        pushObject.on('notification').subscribe((notification: any) => this.displayError('Received a notification', [JSON.stringify(notification)]));

        pushObject.on('registration').subscribe((registration: any) => this.displayError('Device registered', [JSON.stringify(registration)]));

        pushObject.on('error').subscribe(error => this.displayError('Error with Push plugin', [JSON.stringify(error)]));

In Xcode I see that the line: https://github.com/phonegap/phonegap-plugin-push/blob/master/src/ios/PushPlugin.m#L545 is invoked, but the if statement is false.

>>> Do you why this code if condition is false ?

if ([appDelegate respondsToSelector:@selector(checkUserHasRemoteNotificationsEnabledWithCompletionHandler:)]) {

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

iOs env:

iPhone 8, iOs 13.4.1 simulator iPhone 8, iOs 13.3.1 real device push notification enabled

Cordova CLI version and cordova platform version

Using ionic 5

npx cap doctor output:

šŸ’Š Capacitor Doctor šŸ’Š Latest Dependencies: @capacitor/cli: 2.1.0 @capacitor/core: 2.1.0 @capacitor/android: 2.1.0 @capacitor/ios: 2.1.0 Installed Dependencies: @capacitor/cli 1.4.0 @capacitor/core 1.4.0 @capacitor/ios 1.5.2 @capacitor/android 1.5.2

Plugin version

"phonegap-plugin-push": "^2.3.0",
kapten96 commented 4 years ago

having same problem

Jiawei-Nick commented 3 years ago

I also tried using the previously initialized object "this.push" to do call hasPermission() also failed like you do.

I'm able to to do this by using this approach "PushNotification.hasPermission(callBackFunction)" and it success call and return the callback function as expected.

TheMikewithaK commented 3 years ago

Does anyone have a solution for this? I'm having the same problem.