3

I have a very strange issue that has been driving me nuts for a day now. I have a Phonegap Build 3.0 app and am trying to integrate the Push plugin. The problem is that even though I follow the documentation and many, many examples, the dang thing just wont work. I can not get it to fire the success or error callback and the try/catch reports no issues.

Head:

<head>
    <script src="assets/js/myScripts.js"></script>
    <script src="phonegap.js"></script>
    <script type="text/javascript" src="PushNotification.js"></script>
</head>

myScripts.js

var myPushNotification;
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady(){
    myPushNotification = window.plugins.pushNotification;
    try{
        myPushNotification.register(gcmRegistrationSuccessHandler, gcmRegistrationErrorHandler, {"senderID":"I have my Sender ID here","ecb":"onNotificationGCM"});
    }
    catch(e){
        alert(e.message);//******this is never fired******
    }
}

function gcmRegistrationSuccessHandler(result){
    alert("successfully registered);//******this is never fired******
}

function gcmRegistrationErrorHandler(error){
    alert("error registering");//******this is never fired******
}

config.xml contains:

<access origin="*"/>

<gap:platform name="android" />
<gap:platform name="ios" />

<gap:plugin name="com.phonegap.plugins.pushplugin" />

Any help would be greatly appreciated.

Dom
  • 2,569
  • 1
  • 18
  • 28
  • Update: I ran this in Phonegap Build's debug mode and attempted to directly call `myPushNotification.register(gcmRegistrationSuccessHandler, gcmRegistrationErrorHandler, {"senderID":"I have my Sender ID here","ecb":"onNotificationGCM"});` and the log shows it returning as undefined where as calling `myPushNotification = window.plugins.pushNotification;` returns an opject like it should. – Dom Oct 15 '13 at 20:04

1 Answers1

1

Issue resolved. It turns out that the "gcmRegistrationSuccessHandler" callback in myPushNotification.register(gcmRegistrationSuccessHandler, gcmRegistrationErrorHandler, {"senderID":"I have my Sender ID here","ecb":"onNotificationGCM"}); is never called. Only the "onNotificationGCM" is called and you have to take all actions based on that. Sure wish that was documented...

Dom
  • 2,569
  • 1
  • 18
  • 28
  • I am stuck with the exact problem you have had Dom and still can't fix it, I tried anonymous functions as well as callback functions within my app still no luck, I still can't understand how you got it to work? this is my thread http://stackoverflow.com/questions/22350971/phonegap-build-push-notification-android – pleshy Mar 12 '14 at 12:33