【发布时间】:2021-02-23 14:04:00
【问题描述】:
我正在使用 Angular 10 + Cordova + Node 创建一个移动应用程序。在这里我必须发送一些推送通知...我已经使用 Ionic Angular 完成了推送通知 && 我在这个项目中做过(网络版)这与 Firebase 完美配合.. 但不知道如何使用本机(Cordova)。
寻求帮助:
- 如何检索推送通知的设备 ID? (我猜后端部分将是相同的,只需提供移动设备的设备 ID)
这是后端的代码(用于清除混乱)
exports.everyDayDueDate = () => {
task
.find()
.populate([
{
path: "project_id",
model: project,
select: ["project_name"],
},
])
.sort({ status: 1 })
.then((result) => {
result.data.forEach((element) => {
const a = new Date(new Date().toISOString());
const b = new Date(element.taskCompletedate);
if (b.getDate() - a.getDate() == 1) {
User.findById(element.user_id).then((result) => {
if (result) {
let deviceId = result.deviceId;
const payload = {
notification: {
title: element.task_name,
body: "Working!",
},
to: deviceId,
};
const options = {
method: "POST",
uri: "https://fcm.googleapis.com/fcm/send",
body: payload,
json: true,
headers: {
"Content-Type": "application/json",
Authorization:
"key=AAAAL0qgxio:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
},
};
request(options);
}
});
}
});
});
};
我只需要将设备 ID 提供给我的后端,我如何才能得到它
*** 非离子 ***
【问题讨论】:
-
你必须安装cordova设备插件,获取设备ID,然后用ajax发送到后端
标签: javascript angular cordova push-notification native