gpt4 book ai didi

firebase - cordova-plugin-fcm - 未定义 FCMPlugin

转载 作者:行者123 更新时间:2023-12-02 03:11:50 26 4
gpt4 key购买 nike

我正在使用 Ionic 2,并且正在尝试让推送通知正常工作。

我已经在 Firebase 注册了我的应用,并且可以成功推送通知给它。

我现在需要进行设置,以便我可以从我的应用推送通知。所以我决定使用以下 Cordova 插件 ( cordova-plugin-fcm )。

问题一

当我按照它的说明进行操作时,在我的 Ionic 应用程序中执行以下操作:

app.ts

declare var FCMPlugin;
...

initializeApp() {
this.platform.ready().then(() => {
...
FCMPlugin.getToken(
function (token) {
....

我在运行时收到以下错误:

EXCEPTION: Error: Uncaught (in promise): ReferenceError: FCMPlugin is not defined

请问我该如何解决?

问题二

为了从您的应用程序发送通知,Cordova 插件 ( cordova-plugin-fcm ) 执行以下操作:

//POST: https://fcm.googleapis.com/fcm/send 
//HEADER: Content-Type: application/json
//HEADER: Authorization: key=AIzaSy*******************
{
"notification":{
"title":"Notification title", //Any value
"body":"Notification body", //Any value
"sound":"default", //If you want notification sound
"click_action":"FCM_PLUGIN_ACTIVITY", //Must be present for Android
"icon":"fcm_push_icon" //White icon Android resource
},
"data":{
"param1":"value1", //Any data to be retrieved in the notification callback
"param2":"value2"
},
"to":"/topics/topicExample", //Topic or single device
"priority":"high", //If not set, notification won't be delivered on completely closed iOS app
"restricted_package_name":"" //Optional. Set for application filtering
}

这甚至不是 Typescript 或 Javascript。那么它去哪儿了?我只是不明白。任何建议表示赞赏。

最佳答案

您应该在 HTML 索引文件中包含 FCMPlugin.js在应用程序的插件目录中找到js文件的路径示例:MyFCM\plugins\cordova-plugin-fcm\www\FCMPlugin.js

app.controller('AppCtrl', function(FCMPlugin,$scope,$cordovaToast,$cordovaDialogs,ionPlatform) {
// call to register automatically upon device ready
ionPlatform.ready.then(function (device) {
console.log('I am working');
FCMPlugin.onNotification(
function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
$cordovaDialogs.alert(data.notification.body);
}else{
//Notification was received in foreground. Maybe the user needs to be notified.
$cordovaDialogs.alert(data.notification.body);
//$cordovaToast.showShortCenter( JSON.stringify(data) );
}
},
function(msg){
$cordovaToast.showShortCenter('onNotification callback successfully registered: ' + msg);
},
function(err){
$cordovaToast.showShortCenter('Error registering onNotification callback: ' + err);
}
);
});
})

关于firebase - cordova-plugin-fcm - 未定义 FCMPlugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39599340/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com