【问题标题】:Get Device Id Using Angular 10 Cordova使用 Angular 10 Cordova 获取设备 ID
【发布时间】:2021-02-23 14:04:00
【问题描述】:

我正在使用 Angular 10 + Cordova + Node 创建一个移动应用程序。在这里我必须发送一些推送通知...我已经使用 Ionic Angular 完成了推送通知 && 我在这个项目中做过(网络版)这与 Firebase 完美配合.. 但不知道如何使用本机(Cordova)。

寻求帮助:

  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 提供给我的后端,我如何才能得到它

*** 非离子 ***

【问题讨论】:

  • 你必须安装cordova设备插件,获取设备ID,然后用ajax发送到后端

标签: javascript angular cordova push-notification native


【解决方案1】:

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

【讨论】:

  • 我上面提到的不是离子
  • 更新了我的答案。检查这是否有效。如果您需要任何其他帮助,请告诉我。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-08
  • 2020-06-15
  • 1970-01-01
  • 1970-01-01
  • 2019-05-28
  • 1970-01-01
相关资源
最近更新 更多