我正在尝试使用cordova来实现Firbase推送通知。我从这里使用代码为最新的fcm插件说明:Cordova Push Plugin使用cordova的FireBase推送通知
我可以获取注册令牌。然后我尝试使用该令牌从Firebase测试通知模块发送通知。每次我在我的设备运行应用程序,我具有alert-
“消息:onNotification成功注册的回调:OK”
是FCMPlugin.onNotification事件的第二个函数内。
但是第一个函数[我想获取通知的地方]没有被调用。 我没有找到我犯错的地方。这里是我的代码里面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通知已成功传递,但我的问题是当我点击通知时我还想获得警报,同时我使用的是同一个插件,您使用的是哪一个。如果你解决了然后PLZ告诉我。 –
@ KAUSHAL:我更换了插件。以下插件适用于我: [link](https://lokesh-patel.blogspot.com/2016/06/cordova-plugin-firebase-cloud -messaging.html?showComment = 1470646658688#c897350184092951555) –