2016-08-08 29 views
2

コードバスを使用してFirbaseプッシュ通知を実装しようとしています。私はここから最新のfcmプラグのコードをここから使用します:Cordova Push Pluginコードバスを使用したFireBaseプッシュ通知

私はレジスタトークンを得ることができます。その後、そのトークンを使用してFirebaseテスト通知モジュールから通知を送信しようとしました。 「:正常に登録onNotificationメソッドのコールバック:OKメッセージ」

それはFCMPlugin.onNotificationイベントの第2の機能の中にある、私は私のデバイスでアプリケーションを実行するたびに、私はalert-

を持っています。

しかし、[通知を取得したい]という最初の関数は呼び出されません。 私はどこで間違いをしているのか分かりません。ここonDeviceReady内部の私のコードは次のとおりです。

function onDeviceReady() { 
    // Handle the Cordova pause and resume events 
    document.addEventListener('pause', onPause.bind(this), false); 
    document.addEventListener('resume', onResume.bind(this), false); 

    // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here. 
    var parentElement = document.getElementById('deviceready'); 
    var listeningElement = parentElement.querySelector('.listening'); 
    var receivedElement = parentElement.querySelector('.received'); 
    listeningElement.setAttribute('style', 'display:none;'); 
    receivedElement.setAttribute('style', 'display:block;'); 

    //========================= 
    FCMPlugin.getToken(
     function (token) { 
      alert("Token: " + token); 
       cordova.plugins.email.open({ 
        to: '[email protected]', 
        subject: 'Greetings', 
        body: token 
       }); 
     }, 
     function (err) { 
      alert("Error: " + 'error retrieving token: ' + err); 
     } 
    ); 

    FCMPlugin.onNotification(
     function (data) { 
      alert("Notify: " + JSON.stringify(data)); 
      if (data.wasTapped) { 
       //Notification was received on device tray and tapped by the user. 
       alert("Wrapped Notify: " + JSON.stringify(data)); 
      } else { 
       //Notification was received in foreground. Maybe the user needs to be notified. 
       alert("Notify: " + JSON.stringify(data)); 
      } 
     }, 
     function (msg) { 
      alert("Msg: " + 'onNotification callback successfully registered: ' + msg.Notification); 
     }, 
     function (err) { 
      alert("Error: " + 'Error registering onNotification callback: ' + err); 
     } 
    ); 
}; 
+0

ねえ、あなたはどんな解決策を得る:

コルドバ - プラグイン - FCMのドキュメントからREST APIのペイロードの例を参照してください

。?私のFCM通知は正常に配信されましたが、私の問題は通知にタップしたときに私も同じプラグインを使用しています。もしあなたが解決したら、私に教えてください。 –

+0

@ KAUSHAL:プラグインを変更しました。以下のプラグインがうまく機能します。 [link](https://lokesh-patel.blogspot.com/2016/06/cordova-plugin-firebase-cloud -messaging.html?showComment = 1470646658688#c897350184092951555) –

答えて

1

あなたはこのようなonNotificationメソッド関数の前に、あなたのトピックをサブスクライブするために不足している:

FCMPlugin.subscribeToTopic('topic'); 
2

あなたはREST APIのペイロードに"click_action":"FCM_PLUGIN_ACTIVITY"を追加していることを確認します。これはAndroid用である必要があります。これが利用できない場合は、タップされた通知からデータを受信しません(または音が聞こえる)。

//POST: https://fcm.googleapis.com/fcm/send 
//HEADER: Content-Type: application/json 
//HEADER: Authorization: key=AIzaSy******************* 
{ 
    "notification":{ 
    "title":"Notification title", 
    "body":"Notification body", 
    "sound":"default", 
    "click_action":"FCM_PLUGIN_ACTIVITY", // <<<<<<< Must be present for Android 
    "icon":"fcm_push_icon" 
    }, 
    "data":{ 
    "param1":"value1", 
    "param2":"value2" 
    }, 
    "to":"/topics/topicExample", 
    "priority":"high", 
    "restricted_package_name":"" 
} 
関連する問題