An app calls the getDeviceToken API of Device Security Kit to obtain a device token. The app server uses the device token to request the Device Security server to query and manage the app status on the device.
Based on the app status returned by the Device Security server, the app can determine whether it is installed on the device for the first time or whether the user has obtained coupons on the device, supporting new user acquisition campaigns.
The process is as follows:
The following table lists DeviceVerify APIs, including ArkTS APIs and REST APIs. For more information about the APIs, please refer to API Reference.
| API | Description |
|---|---|
| Obtains the device token of a device. | |
| Checks the device token. | |
| Obtains the device marking status. | |
| Sets the device marking status. | |
| Deletes the device marking status. |
import { deviceCertificate } from '@kit.DeviceSecurityKit';
import { BusinessError} from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';const TAG = "DeviceCertificateJsTest";
// Request the device token and process the result.
try {
deviceCertificate.getDeviceToken().then((token) => {
hilog.info(0x0000, TAG, 'Succeeded in executing getDeviceToken');
// You process the device token.
}).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);
}
The device token is valid for 10 minutes.