您好我正在使用离子2并且需要以pubsub格式发送推送通知(用户将内容发布到主题并且订阅者在另一个应用上获得推送通知),已经实现了cordova-plugin-fcm https://github.com/fechanique/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
}
问题:在离子2应用程序中添加此代码的位置,是在完成执行后在.ts文件中添加到函数中还是在哪里?
发布内容的功能代码是: -
代码:job.ts
self.dataService.submitJob(newJob, uid, category)
.then(function (snapshot) {
loader.dismiss()
.then(() => {
self.viewCtrl.dismiss({
newjob: newJob,
uid: uid,
category: category
});
}).then(() => {
let toast = self.toastCtrl.create({
message: 'Job Posted Succesfully',
duration: 3000,
position: 'top'
});
toast.present();
});
}, function (error) {
console.error(error);
loader.dismiss();
});
我想知道的是,我必须在此处调用代码发送推送通知吗?