コードバスを使用して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);
}
);
};
ねえ、あなたはどんな解決策を得る:
コルドバ - プラグイン - FCMのドキュメントからREST APIのペイロードの例を参照してください
。?私のFCM通知は正常に配信されましたが、私の問題は通知にタップしたときに私も同じプラグインを使用しています。もしあなたが解決したら、私に教えてください。 –@ KAUSHAL:プラグインを変更しました。以下のプラグインがうまく機能します。 [link](https://lokesh-patel.blogspot.com/2016/06/cordova-plugin-firebase-cloud -messaging.html?showComment = 1470646658688#c897350184092951555) –