更新记录
1.0.1(2025-03-11)
实现Android(安卓)/iOS(苹果)/HarmonyOS next(纯血鸿蒙)平台获取设备ID
1.0.0(2025-03-11)
实现Android(安卓)/iOS(苹果)/HarmonyOS next(纯血鸿蒙)平台获取设备ID; 可使用uni.getDeviceIdSync和uni.getDeviceId方法获取
平台兼容性
Vue2 | Vue3 |
---|---|
× | √ |
App | 快应用 | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 |
---|---|---|---|---|---|---|
HBuilderX 4.45,Android:5.0,iOS:9,HarmonyNext:支持 | × | × | × | × | × | × |
钉钉小程序 | 快手小程序 | 飞书小程序 | 京东小程序 | 鸿蒙元服务 |
---|---|---|---|---|
× | × | × | × | × |
H5-Safari | Android Browser | 微信浏览器(Android) | QQ浏览器(Android) | Chrome | IE | Edge | Firefox | PC-Safari |
---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | × | × | × |
uni-getdeviceid
使用文档
在main.js文件增加下方代码
import {getDeviceId,getDeviceIdSync} from "@/uni_modules/uu-getdeviceid";
uni.getDeviceId = getDeviceId;
uni.getDeviceIdSync = getDeviceIdSync;
可实现uni.getDeviceIdSync()或者uni.getDeviceId()方法调用方法
// 获取设备ID(同步)
let {
deviceId
} = uni.getDeviceIdSync();
// 获取设备ID(异步)
uni.getDeviceId({
success(res) {
console.log(res);
uni.showToast({
title: "设备ID:" + res.deviceId,
icon: 'none'
});
}
})
参数
Object object
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
success | function | 否 | 接口调用成功的回调函数 |
fail | function | 否 | 接口调用失败的回调函数 |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数
属性 | 类型 | 说明 |
---|---|---|
deviceId | string | 设备Id |
HarmonyOS next权限配置
{
"name": "ohos.permission.STORE_PERSISTENT_DATA",
"usedScene": {
"abilities": [
"EntryAbility"
],
"when": "always"
},
}