dpa99c / cordova-diagnostic-plugin

Cordova/Phonegap plugin to manage device settings
540 stars 361 forks source link

requestRemoteNotificationAuthorization always triggers error callback on iOS during the first request #420

Closed ducile closed 4 years ago

ducile commented 4 years ago

Bug report

CHECKLIST

Current behavior:

When reinstalling the application and requesting remote notification permissions for the first time, the requestRemoteNotificationAuthorization function will always trigger the error callback with Remote notifications authorization was denied even if you accepted the request.

Expected behavior:

The function should go into the success callback and return the status depending on which option was chosen.

Steps to reproduce:

  1. Install an app with that plugin
  2. Trigger the remote notification request for the first time
  3. Set breakpoints in to the success and error callback
  4. Accept the request

Screenshots

Environment information

Runtime issue

iOS build issue:

Related code:

const iosPermissions = cordova.plugins.diagnostic;

function _requestiOSNotificationPermission(serviceDelegate) {
        return new Promise(function (resolve, reject) {
                iosPermissions.requestRemoteNotificationsAuthorization(
                        function (status) {
                            if (status === iosPermissions.permissionStatus.GRANTED) {
                                resolve();
                            } else {
                                // permission denied on ask
                                _noPermissionSnackbar(serviceDelegate, Strings.noPushPermission);

                                reject();
                            }
                        }, function (error) {
                            _noPermissionSnackbar(serviceDelegate, Strings.pushDeniedOnAppLevel);

                            reject(error);
                        },
                        [
                            iosPermissions.remoteNotificationType.ALERT,
                            iosPermissions.remoteNotificationType.SOUND,
                            iosPermissions.remoteNotificationType.BADGE
                        ]
                        , false
                    )
            }.bind(this));
    }

Console output

console output ``` // Paste any relevant JS/native console output here ```


**Other information:**
dpa99c commented 4 years ago

I'm not able to reproduce this issue with the example project app - tested on an iPhone 8 running iOS 14.1 and permission was requested successfully on each clean install.

Please build/run the example app and regression test using it to rule out the cause of the issue being specific to your codebase.

ducile commented 4 years ago

I can confirm that it works fine on the example project. However, I don't really have a clue why it doesn't work in my codebase.

I've just removed the promise wrapping as it could be a potential error case but without success. Do you have any idea where the problem might come from?

dpa99c commented 4 years ago

I'd suggest creating a new test project to track down the cause of the issue in your project: start with just this plugin to eliminate the possibility of conflict with another plugin. Start with the simplest test case to get it working then transition it to your implementation/project to find the cause.

However closing this as you've confirmed the test project works so it's not due to a plugin bug that affects all use cases.

ducile commented 4 years ago

Quick update: I've found the origin of the problem. There was a second call which requested the permission synchronously and therefore wasn't visible in the debugger. That second request caused the permission request function to break.