【问题标题】:Ionic + Capacitor | Getting a Device UUID in iOS device离子+电容|在 iOS 设备中获取设备 UUID
【发布时间】:2021-06-22 09:14:47
【问题描述】:

我正在尝试注册连接 ionic、Firebase 和 Amazon SNS 的应用程序的每台设备。更具体地说,当用户登录包含以下内容的 TokenDTO 时:

  1. deviceToken: 字符串
  2. deviceUuid:字符串
  3. osType : string [用于区分iOS和Android]

必须发送到后端才能在 Amazon SNS 主题上注册 deviceToken。 我遇到的唯一问题是试图唯一标识一个 iOS 设备。在 Android 上,一切都按预期工作(使用 @ionic-native/unique-device-idd),但在 iOS 环境中使用时返回 null。有人可以帮忙吗?提前非常感谢您!

这是我的代码:

registerTokenOnSNS(tokenString): any {
    let tokenDTO: TokenDTO = {
        deviceToken: '',
        imei: '',
        osType: '',
    };
    if (this.platform.is('android')) {
        tokenDTO.osType = 'Android';
    } else {
        tokenDTO.osType = 'iOS';
    }
    tokenDTO.deviceToken = tokenString;
    tokenDTO.imei = this.device.uuid

    return this.http.post<Response>(this.apiBaseUrl + '/register-endpoint', JSON.stringify(tokenDTO)).pipe(
        map((result) => {
            console.log('BE Received Token');
            return result.body;
        })
    );
}

【问题讨论】:

  • 请分享您的代码
  • @RaviAshara 我刚刚更新了我的问题。谢谢!
  • 检查此链接“capacitorjs.com/docs/v2/apis/device”并使用来自Device.getInfouuid
  • 你是在app.module.ts文件中导入import { Device } from '@ionic-native/device/ngx';吗???

标签: ios ionic-framework ionic-native capacitor


【解决方案1】:

我找到了解决方案。每个插件都需要等待设备准备好。用户设备就绪函数并调用get uuid函数。

import { Component } from '@angular/core';
import { Device } from '@ionic-native/device/ngx';
import { Platform } from '@ionic/angular';
@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {
  constructor(
  private device: Device,
  private platform: Platform
) {
 this.getDevice();
}
async getDevice(){
   this.platform.ready().then(() => {      
      const id = this.device.uuid;
    })
 }
  checkLogout() {
    this.commonService.checkLogout();
 }
}

这对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 2015-02-12
    • 2021-04-17
    • 2018-07-15
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多