我正在使用Ionic 2,并试图使推送通知正常工作。cordova-plugin-fcm -FCMPlugin未定义
我已经使用Firebase注册了我的应用程序,并且可以成功向其推送通知。
我现在需要设置,以便我可以从我的应用程序推送通知。所以我决定使用下面的Cordova插件(cordova-plugin-fcm)。
问题1
当我按照它的指示,做在我的应用程序离子如下:
app.ts
declare var FCMPlugin;
...
initializeApp() {
this.platform.ready().then(() => {
...
FCMPlugin.getToken(
function (token) {
....
我在运行时获取以下错误:
EXCEPTION: Error: Uncaught (in promise): ReferenceError: FCMPlugin is not defined
我该如何解决这个问题?
问题2
为了从您的应用程序发送通知,科尔多瓦插件(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
}
这甚至不是打字稿或Javascript。那么它到底在哪里?我只是不明白。任何意见赞赏。
这是工作吗? –
为我的科尔多瓦应用程序工作 – Amjad