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

push.on => "registration" will trigger twice times that only in iOS #57

Closed
bau720123 opened this issue Aug 8, 2015 · 38 comments
Closed
Assignees
Labels
Milestone

Comments

@bau720123
Copy link

according to the "Quick Example"
https://github.com/phonegap/phonegap-plugin-push
I test in Android 4.4.2 and iOS 8.4 that all in real device

when in android,the "registration" behavior only trigger one time
but...
when in ios,the "registration" behavior will trigger twice times

@macdonst
Copy link
Member

macdonst commented Aug 9, 2015

@bau720123 Really, I've never seen the registration trigger twice on iOS. Can you put up a gist of the html/js you are using that can reproduce the problem?

@bau720123
Copy link
Author

hi @macdonst
thanks for your reply
well...the code just like the example code

var push = PushNotification.init({ "android": {"senderID": "my_sender_id"},
         "ios": {}, "windows": {} } );

    push.on('registration', function(data) {
        alert(data.registrationId); //it will trigger twice times in my iOS 8.4
    });

    push.on('notification', function(data) {
        //not try yet...
    });

    push.on('error', function(e) {
        //not try yet...
    });

but I am using PGB (build.phonegap.com) Cli 5.1.1 with all official core plugin from NPM

@macdonst
Copy link
Member

@bau720123 I'm running iOS 8.4 on my test device and I can't reproduce this at all. Do you have a link to the github repo you use to test on PGB?

@bau720123
Copy link
Author

hi @macdonst
problem solved (so strange...)
anyway ~ thanks

@Mojo90
Copy link

Mojo90 commented Aug 31, 2015

@bau720123
what was your Problem?
Because mine is also called twice or sometimes even 3 times.....
My assumption is that it has to do with this plugin: https://github.com/katzer/cordova-plugin-local-notifications but not sure yet

@bau720123
Copy link
Author

hi @Mojo90
have you ever use the old "plugin-notification"
https://github.com/phonegap-build/PushPlugin
if yes,remove it,rebuild it,clean the app's cache
and try again...

@Mojo90
Copy link

Mojo90 commented Sep 1, 2015

no unfortunately not :-(. Still investigating...

@bau720123
Copy link
Author

hi @Mojo90
how about paste your full code here

@Mojo90
Copy link

Mojo90 commented Sep 1, 2015

@bau720123 here is a snippet:
initPushService is called from device-ready method.
and then my registerPushAtServer is called twice, 3x or 4x on iOS. I handle it now and do only update devicetoken on parse.com when it changed. but nevertheless it is a strange behavior

function initPushService(){

var push = PushNotification.init({ 
            "android": {"senderID": "XXXXX"},
            "ios": {}, 
            "windows": {} 
        });

push.on('registration', function(response) {
    registerPushAtServer(response);
});

push.on('notification', function(data) {
    handlePushNotification(data)
});

push.on('error', function(e) {
    // e.message
    console.log("Push Error: " + e);
});

}

it is strange because on android it is only called once.

@bau720123
Copy link
Author

hi @Mojo90
try to just only use "alert(response)" or "console.log(response)" first
to see if it will work only trigger one time
if will,I think maybe your "registerPushAtServer" problem

@Mojo90
Copy link

Mojo90 commented Sep 1, 2015

thanks @bau720123
tried it, but same behavior. I really think that it has some problems with the local notifications plugin from katzer. but couldn't figured out yet whats the problem. really these are two good plugins and the notifications plugin has completely stopped working since I installed this Push Plugin here :-(

@bau720123
Copy link
Author

hi @Mojo90 and @macdonst
for now I am facing the same problem ("registration" will trigger twice times that only in iOS)
I am try to figure out what the problem is...

I am using PGB 5.2.0 + plugin 1.2.3 version from npm + iOS9 (cordova cli maybe no problem,but PGB indeed)

@bau720123 bau720123 reopened this Sep 22, 2015
@Mojo90
Copy link

Mojo90 commented Sep 22, 2015

@bau720123 Are you using Local Notification Plugin as well? Because I think for me it is called twice because I use both plugins. Anyway as mentioned by me it is ok for now because I am only updating sth if Device Token changed otherwise nothing happens...

@bau720123
Copy link
Author

got it
thanks @Mojo90
I will try delete the "Local Notification" first to see if anything change
feedback later...

@bau720123
Copy link
Author

hi @Mojo90
just like you said
is the "the "Local Notification" problem
thanks a lot

@bau720123 bau720123 reopened this Sep 22, 2015
@Mojo90
Copy link

Mojo90 commented Sep 22, 2015

@bau720123 No problem. If you fixed it please let me know. But at the moment I just ignore...

@bau720123
Copy link
Author

hi @Mojo90 and @macdonst
I notice that the problem is not "Local Notification"
for now I am just using core plugin + push plugin
push

but still facing same problem that only in iOS (I am in iOS 9)
when you install your ipa to your ios device

launch it...
first time,the app will ask you if turn on the notification,select yes,after it,trigger only one time

close the app and launch it again...
second time,because first time the app have been ask you before,so...won't ask again,after it, trigger twice time

my full code,index.html

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0">
<title>PhoneGap with jQuery Mobile</title>
<script src="cordova.js" type="text/javascript"></script>
<script type="text/javascript">
document.addEventListener("deviceready", initialize, false);
function initialize()
{
var push = PushNotification.init({ "android": {"senderID": "XXXXYYYZZZ"}, "ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } );

push.on('registration', function(data)
{
alert(data.registrationId);
});

push.on('notification', function(data)
{
alert(data);
});

push.on('error', function(e)
{
alert(e.message);
});
}
</script>
</head>

<body>
</body>
</html>

@bau720123
Copy link
Author

hi @Mojo90 and @macdonst
finally figure it out
according above (PGB 5.2.0 + all latest core plugin + 1.2.3 push + all same code)
ipad mini (9.0 13A344) => have twice problem
iphone 6 plus (8.4.1 12H321) => have no twice problem
so...I guess it is the iOS version problem

@wakeupmh
Copy link

wakeupmh commented Oct 1, 2015

Hi @bau720123 , I have tested your code, but in my app it doesn't works, Can you help me ?

@macdonst
Copy link
Member

macdonst commented Oct 1, 2015

@bau720123 Yeah, I've been able to reproduce this on an iOS9 device as well.

@macdonst macdonst added the bug label Oct 1, 2015
@macdonst macdonst added this to the Release 1.4.0 milestone Oct 1, 2015
@macdonst macdonst self-assigned this Oct 1, 2015
@bau720123
Copy link
Author

hi @wakeupmh
is your deviceready trigger ?
please confirm this first

@bau720123
Copy link
Author

thanks @macdonst
glad to hear that you reproduce this on iOS9 !!!

@wakeupmh
Copy link

wakeupmh commented Oct 1, 2015

Yes @ bau720123 , I use deviceready trigger , Can I use another way to show an alert with my registration key ?, I just wanna a test with this plugin, because when i called the function it does not show anything to me in app build

@bau720123
Copy link
Author

hi @wakeupmh
android or ios ?
version ?
are you sure the plugin install correct ?
PGB version ?

@wakeupmh
Copy link

wakeupmh commented Oct 1, 2015

hello @bau720123, In a first moment this app is only for Android version:4.4.2. I'm using a PGB without interface, directly on Sublime text for example, so I only included this following tag: <gap:plugin name="phonegap-plugin-push" source="npm" /> in my config.xml. I'm using phonegap/cordova CLI 5.2.

@bau720123
Copy link
Author

hi @wakeupmh
what tag ?
I can't see it...

@wakeupmh
Copy link

wakeupmh commented Oct 1, 2015

sorry, this tag: gap:plugin name="phonegap-plugin-push" source="npm"

@bau720123
Copy link
Author

hi @wakeupmh
if you are using PGB (build.phonegap.com)
please use 1.2.3 version for now

<gap:plugin name="phonegap-plugin-push" source="npm" version="1.2.3" />

and...if you have other question
please reopen a new one
because this article topic is "rigger twice times" problem
thanks

@fredgalvao
Copy link
Collaborator

@bau720123, @wakeupmh There is not need to specify 1.2.3 for PhonegapBuild anymore. See the README.

@bau720123
Copy link
Author

hi @fredgalvao
I know PGB support gradle build for now
but look at this
http://community.phonegap.com/nitobi/topics/gradle-support-enabled-for-android-builds
I am "ColinBau"

so...I suggest if you are using PGB,1.2.3 version for now

@fredgalvao
Copy link
Collaborator

I see... that's bad news huh.

Well, might as well mention that it's a temporary workaround, so people don't stick with older versions of the plugin unnecessarily.

@macdonst
Copy link
Member

@bau720123 can you test with the code that is currently in master? I've merged PR #215 that fixes the issue with the local notifications plugin and I believe it also takes care of this double registration problem. It removes an unnecessary call to registerForRemoteNotifications which could cause the double registration event. Now, I can no longer reproduce the issue.

@bau720123
Copy link
Author

hi @macdonst
so you want me to readd the plugin again and test with this situation ? (double registration problem)

cordova plugin add https://github.com/phonegap/phonegap-plugin-push
or
cordova plugin add "phonegap-plugin-push"

@macdonst
Copy link
Member

Try the

cordova plugin add https://github.com/phonegap/phonegap-plugin-push

Method as it will get the latest code.

On Oct 10, 2015 20:13, "包四維" [email protected] wrote:

hi @macdonst https://github.com/macdonst
so you want me to readd the plugin again and test with this situation ?

cordova plugin add https://github.com/phonegap/phonegap-plugin-push
or
cordova plugin add "phonegap-plugin-push"


Reply to this email directly or view it on GitHub
#57 (comment)
.

@bau720123
Copy link
Author

hi @macdonst
the issue seem solved
thanks

@macdonst
Copy link
Member

Closing as per @bau720123

@19akash91
Copy link

19akash91 commented May 26, 2016

hi @bau720123 sir
i am added cordova plugin add "phonegap-plugin-push" this plugin but not call registration method and error method plz help me

code is here :

var push = PushNotification.init({
android: {
senderID: "*********"
},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
//alert("push is : "+push);
//var push = Scopes.get('push');
push.on('registration', function(data) {alert("in push registration");
device=data.registrationId;
localStorage.setItem('device_id',device);
alert("device id is : "+localStorage.getItem('device_id'));
});
push.on('notification', function(data) {
});
push.on('error', function(e) {
// e.message
alert("ErrorCallback "+e.message);
});
}

@lock
Copy link

lock bot commented Jun 4, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

6 participants