中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何获取获取OAID信息
微信扫码分享
import { identifier }from '@kit.AdsKit'; // 使用Promise方式 private getOaidByPromise() { try { // 获取OAID信息 identifier.getOAID().then((data: string) => { this.oaid = data; hilog.info(0x0000, 'testTag', '%{public}s', 'getAdsIdentifierInfo by promise success'); }).catch((err: BusinessError) => { hilog.error(0x0000, 'testTag', '%{public}s', `getAdsIdentifierInfo failed, message: ${(err as BusinessError).message}`); }) } catch (err) { hilog.error(0x0000, 'testTag', '%{public}s', `get oaid by callback catch error: ${err.code} ${err.message}`); } } // 使用Callback回调方式 private getOaidByCallback() { try { identifier.getOAID((err: BusinessError, data: string) => { if (err.code) { hilog.error(0x0000, 'testTag', '%{public}s', 'getAdsIdentifierInfo failed, message: ${err.message}'); } else { this.oaid = data; hilog.info(0x0000, 'testTag', '%{public}s', 'getOaidFromOaidSaAPi by callback success'); } }); } catch (err) { hilog.error(0x0000, 'testTag', '%{public}s', `get oaid by callback catch error: ${err.code} ${err.message}`); } }