更新记录
1.0.0(2025-10-01)
首发
平台兼容性
uni-app(4.19)
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 | 鸿蒙插件版本 |
---|---|---|---|---|---|---|---|---|---|
- | - | - | - | - | - | - | - | 12 | 1.0.0 |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
- | - | - | - | - | - | - | - | - | - | - |
uni-app x(4.19)
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
- | - | - | - | - | - |
abc-device
鸿蒙设备ID获取插件,支持获取AAID、OAID、ODID等设备标识符。
功能说明
- AAID: 广告标识符 (Advertising ID)
- OAID: 开放匿名设备标识符 (Open Anonymous Device Identifier)
- ODID: 开放设备标识符 (Open Device Identifier)
使用方法
import { getDeviceIds, getAAID, getOAID, getODID } from '@/uni_modules/abc-device'
// 获取所有设备ID
getDeviceIds().then(result => {
console.log('设备ID信息:', result)
console.log('AAID:', result.aaid)
console.log('OAID:', result.oaid)
console.log('ODID:', result.odid)
if (result.error) {
console.log('错误信息:', result.error)
}
})
// 单独获取AAID
getAAID().then(aaid => {
console.log('AAID:', aaid)
}).catch(error => {
console.error('获取AAID失败:', error)
})
// 单独获取OAID
try {
const oaid = getOAID()
console.log('OAID:', oaid)
} catch (error) {
console.error('获取OAID失败:', error)
}
// 单独获取ODID
try {
const odid = getODID()
console.log('ODID:', odid)
} catch (error) {
console.error('获取ODID失败:', error)
}
配置要求
1. 权限配置
需要在 manifest.json
的 app-plus
-> distribute
-> harmony
-> permissions
中添加以下权限:
{
"app-plus": {
"distribute": {
"harmony": {
"permissions": [
"ohos.permission.APP_TRACKING_CONSENT"
]
}
}
}
}
2. 模块依赖
确保在鸿蒙项目的 oh-package.json5
中包含以下依赖:(不用修改)
{
"dependencies": {
"@kit.BasicServicesKit": "file:../../../../../../../.hvigor/cache/ohpm/registry_cache/@ohos+basic-services-kit/1.0.0/oh_modules/@ohos/basic-services-kit",
"@kit.AdServicesKit": "file:../../../../../../../.hvigor/cache/ohpm/registry_cache/@ohos+ad-services-kit/1.0.0/oh_modules/@ohos/ad-services-kit"
}
}
3. 应用配置
在鸿蒙应用的 module.json5
中添加权限声明:
{
"module": {
"requestPermissions": [
{
"name": "ohos.permission.APP_TRACKING_CONSENT",
"reason": "$string:permission_reason",
"usedScene": {
"abilities": ["EntryAbility"],
"when": "inuse"
}
}
]
}
}
注意事项
- AAID获取: 需要用户授权APP_TRACKING_CONSENT权限,首次调用可能需要用户同意
- OAID/ODID获取: 通常不需要特殊权限,但在某些设备上可能不可用
- 错误处理: 建议使用getDeviceIds()方法,它会尝试获取所有ID并提供详细的错误信息
- 隐私合规: 使用设备ID时请遵守相关隐私法规和平台政策