2014-05-18 9 views
5

Sto provando a utilizzare il plugin per la compilazione delle notifiche push di PushMail Push ma i callback di registerDevice non si attivano mai sul mio dispositivo Android, tuttavia la funzione initPushwoosh viene attivata perché vedo l'avviso dalla chiamata per avvisare ("initPushwoosh") nel seguente codiceplug-in phonegap pushwoosh registerDevice le funzioni di callback non si accendono mai su Android

di seguito è riportato il mio config.xml

<?xml version="1.0" encoding="UTF-8"?> 

<!-- config.xml reference: https://build.phonegap.com/docs/config-xml --> 
<widget xmlns  = "http://www.w3.org/ns/widgets" 
     xmlns:gap = "http://phonegap.com/ns/1.0" 
     id  = "com.phonegap.hello-world" 
     version = "1.0.0"> 

    <name>Push notification</name> 

    <description> 
     Camera example app. 
    </description> 

    <author href="http://phonegap.com" email="[email protected]"> 
     PhoneGap Team 
    </author> 

    <preference name="phonegap-version" value="3.3.0" /> 

    <gap:plugin name="org.apache.cordova.core.camera" /> 

    <plugin name="PushNotification" 
     value="com.pushwoosh.plugin.pushnotifications.PushNotifications" onload="true"/> 

    <access origin="*.pushwoosh.com" /> 
</widget> 

ed ecco la mia index.js, ho appena sto cambiando il progetto id e AppID a xxxx in modo che io non rivelare per sbaglio troppo.

var app = { 
    // Application Constructor 
    initialize: function() { 
     this.bindEvents(); 
    }, 
    // Bind Event Listeners 
    // 
    // Bind any events that are required on startup. Common events are: 
    // 'load', 'deviceready', 'offline', and 'online'. 
    bindEvents: function() { 
     document.addEventListener('deviceready', this.onDeviceReady, false); 
    }, 
    // deviceready Event Handler 
    // 
    // The scope of 'this' is the event. In order to call the 'receivedEvent' 
    // function, we must explicity call 'app.receivedEvent(...);' 
    onDeviceReady: function() { 
     alert("onDeviceReady"); 
     app.initPushwoosh(); 
     app.receivedEvent('deviceready'); 

    }, 

    initPushwoosh: function() { 
     alert("initPushwoosh"); 
      var pushNotification = window.plugins.pushNotification; 
      pushNotification.registerDevice(
      { projectid: "XXX-XXX-XXXX 3", appid : "XXXXX-XXXXX" }, 
       function(status) { 
        var pushToken = status; 
        alert('push token: ' + pushToken); 
       }, 
       function(status) { 
        alert(JSON.stringify(['failed to register ', status])); 
      }); 
      document.addEventListener('push-notification', function(event) {    
       var title = event.notification.title; 
       var userData = event.notification.userdata; 
       if (typeof(userData) != "undefined") { 
        alert('user data: ' + JSON.stringify(userData)); 
       }  
       navigator.notification.alert(title); 
      }); 
    }, 
    // Update DOM on a Received Event 
    receivedEvent: function(id) { 
     var parentElement = document.getElementById(id); 
     var listeningElement = parentElement.querySelector('.listening'); 
     var receivedElement = parentElement.querySelector('.received'); 

     listeningElement.setAttribute('style', 'display:none;'); 
     receivedElement.setAttribute('style', 'display:block;'); 

     console.log('Received Event: ' + id); 
    }, 

    takePicture: function() { 
     navigator.camera.getPicture(function(imageURI) { 
     alert(imageURI); 
     }, 
     function(message) { 
     alert(message); 
     }, 
     { 
     quality: 50, 
     destinationType: Camera.DestinationType.FILE_URI 
     }); 
    } 
}; 

qualsiasi aiuto sarebbe molto apprezzato ... grazie!

risposta

0

Usi l'ultima versione del plug-in? In tal caso si prega di controllare l'ultima guida: http://www.pushwoosh.com/programming-push-notification/android/android-additional-platforms/phonegapcordova-sdk-integration/

E 'stato cambiato di recente e la funzione initPushwoosh si presenta così:

function initPushwoosh() 
{ 
    var pushNotification = window.plugins.pushNotification; 

    //set push notifications handler 
    document.addEventListener('push-notification', function(event) { 
     var title = event.notification.title; 
     var userData = event.notification.userdata; 

     if(typeof(userData) != "undefined") { 
      console.warn('user data: ' + JSON.stringify(userData)); 
     } 

     navigator.notification.alert(title); 
    }); 

    //initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start. 
    pushNotification.onDeviceReady({ projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID" }); 

    //register for pushes 
    pushNotification.registerDevice(
     function(status) { 
      var pushToken = status; 
      console.warn('push token: ' + pushToken); 
     }, 
     function(status) { 
      console.warn(JSON.stringify(['failed to register ', status])); 
     } 
    ); 
} 

Inoltre si potrebbe desiderare di controllare due AndroidManifest.xml. Sfortunatamente è davvero facile sbagliarlo: ((

+1

Shader, sto utilizzando PhoneGap compilazione in modo che la mia comprensione è che un ll ho bisogno di fare è aggiungere queste 2 linee (sotto) al file config.xl e che build phonegap userà l'ultimo plugin di pushwoosh e anche creare il file AdroidManifest.xml per me ... hai usato phonegap build con successo per Questo? gabriel

+0

il problema è che Windows. i plug-in non sono definiti, quindi ovviamente window.plugins.PushNotification non è definito e l'app esplode su questa riga var pushNotification = window.plugins.PushNotification; – gabriel

+0

Vedo, per PGB si prega di utilizzare il codice originale, il plug-in su PGB non è ancora aggiornato (impiega anni con il team PGB). In config.xml la tua voce non è corretta allora. Dovrebbe essere come: http://www.pushwoosh.com/programming-push-notification/android/android-additional-platforms/phonegap-build/ shader

1

Cordova ha sostituito window.plugins con la funzione cordova.require() È necessario cercare lo spazio dei nomi in cui è definito il plug-in. Per pushwoosh è: "com .pushwoosh.plugins.pushwoosh.PushNotification"

così, invece di:

var PushNotification = window.plugins.PushNotification; 

provare questo:

var PushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification"); 
Problemi correlati