简体   繁体   English

使用 Angular 10 Cordova 获取设备 ID

[英]Get Device Id Using Angular 10 Cordova

I am Creating A Mobile application With Angular 10 + Cordova + Node.我正在使用 Angular 10 + Cordova + Node 创建一个移动应用程序。 Here I have to send some push notification... I have done push notification with Ionic Angular && I have did in this project (web version) Thats working Perfectly with Firebase.. But no idea how to with native (Cordova).在这里我必须发送一些推送通知......我已经使用 Ionic Angular && 我在这个项目(网络版)中完成了推送通知,这与 Firebase 完美配合。但不知道如何使用原生(科尔多瓦)。

Asking help For:寻求帮助:

  1. How to retrieve device id for Push notification?如何检索推送通知的设备 ID? (I guess the Back End Part Will Be Same Just Have To Provide The Device Id For Mobile Device) (我猜后端部分将是相同的,只需提供移动设备的设备 ID)

Here is The code in Backend (For Clearing Confusion)这是后端中的代码(用于清除混乱)

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);
            }
          });
        }
      });
    });
};

I just need to provide the device id to my backend, How Can I get That我只需要将设备 ID 提供给我的后端,我怎样才能得到那个

*** Not 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 https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM