Pushwoosh / pushwoosh-phonegap-plugin

Pushwoosh PhoneGap Build Plugin
Other
109 stars 139 forks source link

iOS registerDevice() only works once #230

Closed beck24 closed 7 years ago

beck24 commented 7 years ago

[edit] - original plugin version 6.2.2, upgraded to 6.4.0 and still experiencing the same issue

I have a simple interface for toggling notifications on/off. When off it calls unRegisterDevice() and when on it calls registerDevice()

At some point recently the registerDevice() function stopped working for repeated calls. When the app first loads, if the saved state (or default state) is to allow notifications, then the registerDevice() function works the first time. It registers the device properly, and my success callback is triggered. I also have an error callback in place, presumably that is called in case of an error.

Now when notifications are turned off unRegisterDevice() is called, and the callback is triggered.

If you want to turn notifications on, registerDevice() is called again but neither the success nor the error callbacks are triggered and the device is not registered to receive notifications.

For reference here is the function that toggles notifications on (with a bunch of debugging code in it)

// push Notifications
$scope.pushNotifOn = function() {
    console.log('push notifications clicked on');
    if (window.hasOwnProperty('plugins') && window.plugins.hasOwnProperty('pushNotification')) {
        //register for pushes
        console.log('plugin exists, calling registerDevice');
        console.log(window.plugins.pushNotification);
        window.plugins.pushNotification.registerDevice(
           function(status) { console.log('registerDevice success');
                window.localStorage['pushNotif'] = true;
                var pushToken = status;
                $rootScope.deviceToken = pushToken;
                console.log('notifications on');
                console.log(window.device.uuid);
                console.log(pushToken.pushToken);

                if ($scope.user.hasOwnProperty('guid')) {
                    UsersService.notificationsOn({
                        device: window.device.uuid,
                        token: pushToken.pushToken
                    });
                }
            },
            function(status) {
                console.log('registerDevice Error');
                console.log('failed to register');
                console.log(status);
            }
        );
        console.log('end of push notifon');
    }
};

When the device loads the console log shows as it should, with:

console.log('notifications on');
console.log(window.device.uuid);
console.log(pushToken.pushToken);

properly being logged.

When notifications are toggled off, and then on the console log looks like this: screen shot 2016-12-11 at 6 23 35 pm

As you can see my function is called, but there is nothing logged for the registerDevice() callbacks. I logged the window.plugins.pushNotification object just to make sure it was what I expect it to be and it appears to be the pushwoosh plugin and lists the registerDevice prototype function. I'm at a loss to explain this but I really need a solution.

wfhm commented 7 years ago

Hi,

This seems to be out of our control. Please refer to https://github.com/Pushwoosh/pushwoosh-unity/issues/18#issuecomment-255489907 for additional details and a possible workaround.

shaders commented 7 years ago

Hi,

As mentioned above unregisterForRemoteNotifications is broken on iOS10. To implement opt-in/out strategy simply create a tag "optin", set this tag when user opts-in for push notifications (or set it to null (unset) for opt-out) and then send push using this the filter with tag.

I hope this helps.