使用Angular 10 Cordova获取设备Id



我正在用Angular 10 + Cordova + Node创建一个移动应用程序。这里我必须发送一些推送通知……我用Ionic Angular做过推送通知我已经在这个项目(网页版)与Firebase完美的工作。但是不知道如何使用native (Cordova)。

求助For:

  1. 如何检索设备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到我的后端,我怎么能得到那个

***非Ionic ***

cordova plugin add cordova-plugin-device

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(device.uuid);
}

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device/index.html

最新更新