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

iOS Push register twice on first install #1438

Open
Bart-Holland opened this issue Dec 7, 2016 · 17 comments
Open

iOS Push register twice on first install #1438

Bart-Holland opened this issue Dec 7, 2016 · 17 comments

Comments

@Bart-Holland
Copy link

Expected Behaviour

On first boot of the app, after accepting to recieve push notifications for this app, you would expect the registration to trigger once.

Actual Behaviour

On first 'boot' of the app, after accepcting to recieve push notifications for this app, the push register is triggered twice, though the PushNotification.init is only done once. This results in Google errors 5: ''Operation In Progress, Another similar operation is in progress. This one was canceled."

Steps to Reproduce

Set an alert in the 'on registration' listener.
When you delete the app, install and then run the app. You will be asked if you would like to accept push notifications for this app. After accepting, you will recieve the alert twice.
Every other time here after, you will not recieve the alert twice. Unless you remove the app and do this all over again.

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

iOS 9.3
iOS 9.3.1
iOS 9.3.2
iOS 9.3.3
iOS 9.3.4
iOS 9.3.5

iOS 10
iOS 10.0.2
iOS 10.0.3
iOS 10.1
iOS 10.1.1

Cordova CLI version and cordova platform version

cordova --version:  5.2.0
cordova platform version iOS 4.2.0

Plugin version

phonegap-plugin-push:  1.8.2

Sample Code that illustrates the problem

onDeviceReady: function () {

        var that = this;

        // set other listeners
        this.deviceIsReady = true;
        navigator.splashscreen.hide();

        //Get topics from local storage
        var myTopics = JSON.parse(HKV.getLocalStorageItem("myLocations")) || [];

        //Trim Whitespaces
        if (myTopics !== [null]) {
            $.each(myTopics, function (key, value) {
                myTopics[key] = value.replace(" ", "");
            });
        }

        //Default Topic for all users
        myTopics.push("MHW");

        //Push initialiseren
        APP.initPush(myTopics);
        APP.setPushListeners();

    },

    initPush: function (myTopics) {

        APP.push = PushNotification.init({
            android: {
                senderID: APP.senderId,
                sound: true,
                vibrate: true,
                clearNotifications: true,
                topics: myTopics
            },
            ios: {
                senderID: APP.senderId,
                alert: true,
                badge: true,
                sound: true,
                topics: myTopics
            },
            windows: {}
        });
    },

    setPushListeners: function () {

        //when push is registered
        APP.push.on('registration', function (data) {
            alert('on registration');            
            APP.pushRegistration(data);
        });

        //when push notification is recieved
        APP.push.on('notification', function (data) {            
            APP.pushNotification(data);
        });

        //when push recieves an error
        //TODO: kijken of de global function setAlert gebruikt kan worden
        APP.push.on('error', function (e) {
            alert(e.message);
        });
    },

Another way to reproduce

In the plugin directory open www and edit push.js on line 36 add
alert('emit');
On first run you will also see this one twice.

Logs taken while reproducing problem

Can't find logs: how to capture logging?

@avishaan
Copy link

avishaan commented Dec 8, 2016

can confirm I am seeing this same behaviour

@elsesiy
Copy link

elsesiy commented Feb 16, 2017

The issue is still current with the latest versions of cordova and the plugin.
cordova 6.5.0
phonegap-plugin-push 1.9.2

Is someone working on this?

@manuelnaturalcycles
Copy link

im having this same issue too. ;(

@HectorFGarcia
Copy link

I have it too.

Plugin 1.8.4
iOS 10.3.2
Ionic 2.2

@HectorFGarcia
Copy link

By the way, this problem is generating another one: A code 5* com.google.iid error making the notification system fail.

  • Operation In Progress Another similar operation is in progress. This one was canceled.

@macdonst
Copy link
Member

macdonst commented Jul 4, 2017

I can't reproduce this. Does anyone have the logs from Xcode while starting their app that show this problem?

@tombell
Copy link

tombell commented Jul 20, 2017

I believe I am encountering something similar, the first registration event happens before I've even tapped "Allow" on the prompt for allowing notifications, then the 2nd event happens after I've tapped "Allow".

2017-07-20 10:41:22.593022+0100 Redacted[406:40103] PushPlugin.register: setting badge to false
2017-07-20 10:41:22.593034+0100 Redacted[406:40103] PushPlugin.register: clear badge is set to 0
2017-07-20 10:41:22.593116+0100 Redacted[406:40103] PushPlugin.register: better button setup
2017-07-20 10:41:22.596047+0100 Redacted[406:40103] GCM Sender ID (null)
2017-07-20 10:41:22.596079+0100 Redacted[406:40103] Using APNS Notification
2017-07-20 10:41:22.644108+0100 Redacted[406:39542] Push Plugin register success: <XXXXXXXX c3ea8cae 280d0a39 XXXXXXXX 6d83ee4a f37167da b0b4f948 9e324960>
2017-07-20 10:41:22.650079+0100 Redacted[406:39542] Registration Done: {"registrationId":"XXXXXXXXXXXXXX"}
2017-07-20 10:41:38.603170+0100 Redacted[406:39542] active
2017-07-20 10:41:38.603454+0100 Redacted[406:39542] PushPlugin skip clear badge
2017-07-20 10:41:22.644108+0100 Redacted[406:39542] Push Plugin register success: <XXXXXXXX c3ea8cae 280d0a39 XXXXXXXX 6d83ee4a f37167da b0b4f948 9e324960>
2017-07-20 10:41:22.650079+0100 Redacted[406:39542] Registration Done: {"registrationId":"XXXXXXXXXXXXXX"}

@paulstraw
Copy link

I'm seeing the same behavior as @tombell in 2.0.0. Before the "Allow" button is tapped, I get a registration event, and then another when "Allow" is tapped, as expected. Curiously, they both have the same registrationId, as seen in Tom's log output above.

@jespertheend
Copy link

jespertheend commented Nov 13, 2017

Not sure to what extent this is related, but I was trying to change some UI after the user responded to the permission dialog. I'm only getting one registration event though. But it fires before the user responded to the dialog.
But I found a solution for this from this answer. I figured you can use the active and resign events to check when the user responded to the dialog. I don't know if this is documented anywhere but these events are built-in in cordova. document.addEventListener("resign", someFunction) should do the job.
I hope that helps someone.

edit: It seems like sometimes PushNotification.hasPermission returns {isEnabled:false} even if the user accepted the dialog. The isEnabled state doesn't get updated in time, so I think I'll have to put a timeout on it and check for PushNotification.hasPermission a few milliseconds after the active event fires.

@jspizziri
Copy link

Also seeing registration firing prior to "Allow" being clicked in [email protected], [email protected]

@kd8ssq
Copy link

kd8ssq commented Mar 15, 2018

If I put alerts in place to trace the call flow, I see the registration event being called twice.

I have the same setup as @jspizziri and I'm seeing the exact same thing. The registration event is being fired long before Allow or Deny is clicked on the iOS device.

@stale
Copy link

stale bot commented Jun 3, 2018

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.

@stale stale bot added the wontfix label Jun 3, 2018
@macdonst macdonst added the retest label Jun 4, 2018
@stale stale bot removed the wontfix label Jun 4, 2018
@MatthewPringle
Copy link

Still happening in 2.2.3 as @kd8ssq describes. On first install, when the question is asked by the OS on .init the registration event fires, both times returning the same id.

@sjregan
Copy link

sjregan commented Feb 11, 2019

Also seeing registration firing prior to "Allow" being clicked in [email protected], [email protected]

Has anyone figured a way around this?

@MatthewPringle
Copy link

Also seeing registration firing prior to "Allow" being clicked in [email protected], [email protected]

Has anyone figured a way around this?

It seems to work fine. It does send the registration but if they don't click allow the app wont get sns so it doesnt matter as such.

@sjregan
Copy link

sjregan commented Feb 11, 2019

It seems to work fine. It does send the registration but if they don't click allow the app wont get sns so it doesnt matter as such.

Thanks, that is a good point. A concern for those with large number of installs would be costs/exceeding quotas with your push notifications provider for dead notifications.

@MatthewPringle
Copy link

In AWS SNS the endpoint becomes disabled if they decline from what I could work out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests