智能客服
你问我答,随时在线为你解决问题

























本模块提供应用设备状态检测能力,对应用在某台设备上的使用状态进行管理和检测,用于判断应用是否在该设备上首次安装,或在该设备上用户是否已获取了优惠券等的状态检测,以支撑业务进行新用户营销活动。
起始版本: 5.0.0(12)
import { deviceCertificate } from '@kit.DeviceSecurityKit'; getDeviceToken(): Promise<string>
获取本设备的DeviceToken。使用Promise异步回调。
元服务API:从版本5.0.2(14)开始,该接口支持在元服务中使用。
系统能力:SystemCapability.Security.DeviceCertificate
起始版本:5.0.0(12)
返回值:
类型 | 说明 |
|---|---|
Promise<string> | Promise对象,返回本设备的DeviceToken。 |
错误码:
以下错误码的详细介绍请参见ArkTS API错误码。
错误码ID | 错误信息 |
|---|---|
has no permission. | |
internal error. | |
access cloud server fail. |
示例:
import { deviceCertificate } from '@kit.DeviceSecurityKit';
import { BusinessError} from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
const TAG = "DeviceCertificateJsTest";
// 请求deviceToken,并处理结果
try {
deviceCertificate.getDeviceToken().then((token) => {
hilog.info(0x0000, TAG, 'Succeeded in executing getDeviceToken');
// 开发者处理deviceToken
}).catch((err: BusinessError) => {
hilog.error(0x0000, TAG, 'getDeviceToken failed! %{public}d %{public}s', err.code, err.message);
});
} catch (err) {
let error: BusinessError = err as BusinessError;
hilog.error(0x0000, TAG, 'getDeviceToken failed! %{public}d %{public}s', error.code, error.message);
} 智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功