Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

PushPlugin.m init() should send pending notification when js side is ready #658

Closed
@jimmy-tfp

Description

On iOS:

Expected Behaviour

When your app is "not running" and you click a notification for that app, in PushPlugin.init() it finds "notificationMessage" and sends that to the app when the app is ready

Actual Behaviour

When your app is "not running" and you click a notification for that app, in PushPlugin.init() it finds "notificationMessage" and sends that to the app right away and the app has not had a chance to setup the rest of the calls needed to catch the notification.

Reproduce Scenario (including but not limited to)

  1. Kill your app
  2. Send it a notification
  3. Click on the notification
  4. Note it does not show up

Steps to Reproduce

see above

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

iOS 9.2.1, 6 and 6p

Sample Push Data Payload

payload = json.dumps({
'aps': {
'alert': 'Push Test %d: %s' % (ident, str(uuid.uuid4())[:8]),
'badge': 4
}
})

Sample Code that illustrates the problem

here is my service initialize:

function initialize () {

        if (window.cordova) {

            $rootScope.$on('$cordovaPushV5:notificationReceived', function (event, notification) {

                console.log('$cordovaPushV5:notificationReceived');
                //alert('notificationReceived: ' + JSON.stringify(notification));

                if(notification.message) {

                }

                if(notification.additionalData && typeof notification.additionalData.foreground != 'undefined' && !notification.additionalData.foreground) {
                    $state.go('tab.inbox');
                }
            });


            var options = {
                android: {
                    senderID: ''
                },
                ios: {
                    alert: true,
                    badge: true,
                    sound: false,
                    clearBadge: true
                },
                windows: {}
            };

            $cordovaPushV5.initialize(options).then(function(deviceToken) {

                console.log('$cordovaPushV5:initialize');

                $cordovaPushV5.register().then(function(deviceToken) {

                    console.log('$cordovaPushV5:register');
                    console.log('deviceToken: ' + deviceToken);
                    peckService.saveDeviceToken($auth.getPayload().sub, deviceToken);

                    $cordovaPushV5.onError();
                    $cordovaPushV5.onNotification();

                    console.log('$cordovaPushV5:ready for notifications');

                }, function(err) {
                    console.log('register error: ' + err)
                });
            }, function(err) {
                console.log('initialize error: ' + err)
            });

        }
    }

Logs taken while reproducing problem

not sure how to get them...

The "Fix"

to "fix" this I put a delay before sending out the initial notification.

// if there is a pending startup notification, go ahead and process it after a delay to let the js warmup
if (notificationMessage) {
dispatch_async(dispatch_get_main_queue(), ^{
// it works everytime with 0.3 so 1.2 is just majik
[self performSelector:@selector(notificationReceived) withObject:nil afterDelay: 1.2];
});
}

However it seems like the real fix should be to have a new method in the plugin called "IamFinallyReadyToReceiveThatOpeningNotificationNow" that would queue the notification when the js size is all ready.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions