【发布时间】:2016-09-20 16:27:48
【问题描述】:
我正在使用 Ionic 2,并且正在尝试让推送通知正常工作。
我已经在 Firebase 中注册了我的应用,并且可以成功向其推送通知。
我现在需要进行设置,以便可以从我的应用推送通知。所以我决定使用下面的 Cordova 插件 (cordova-plugin-fcm)。
问题 1
当我按照它的说明操作时,在我的 Ionic 应用程序中执行以下操作:
app.ts
declare var FCMPlugin;
...
initializeApp() {
this.platform.ready().then(() => {
...
FCMPlugin.getToken(
function (token) {
....
我在运行时收到以下错误:
异常:错误:未捕获(承诺中):ReferenceError:FCMPlugin 是 未定义
请问我该如何解决?
问题 2
为了从您的应用发送通知,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。那么它要去哪里呢?我只是不明白。任何建议表示赞赏。
【问题讨论】:
标签: firebase push-notification cordova-plugins ionic2 firebase-cloud-messaging