Vendor channels

更新时间:
复制 MD 格式

This topic describes how to use the HarmonyOS software development kit (SDK) to integrate the HarmonyOS channel.

Features

By default, the SDK uses the Alibaba Cloud persistent connection channel for pushes. The SDK also supports sending pushes through the HarmonyOS push service.

After you integrate the HarmonyOS push service, you can send pushes through the HarmonyOS channel when the application is offline.

Prerequisites

Enable the push service, obtain the Client ID, request scenario-based consumption rights, and obtain the Push Token. For more information, see the HarmonyOS Push Service development preparation document.

Create and download the service account key for the Push Service API. For more information, see API Console User Guide - Service Account Keys. Then, configure the HarmonyOS channel. For more information, see Configure vendor channel keys.

Register the device. For more information, see Integrate the HarmonyOS SDK.

Register the HarmonyOS Push Token

After you register the device, obtain the HarmonyOS Push Token and register it with the Alibaba Cloud Mobile Push platform using the SDK. This completes the integration of the HarmonyOS channel. The following code provides an example:

import { aliyunPush } from '@aliyun/push';
import { pushService } from '@kit.PushKit';
import { BusinessError } from '@kit.BasicServicesKit';

pushService.getToken().then((pushToken) => {
  // ************* Register PushToken: start *************
  aliyunPush.registerThirdToken(pushToken, (error) => {
    if (error) {
      console.error(`Failed to register the PushToken. Error code: ${error.code}. Error message: ${error.message}`);
      return;
    }
    console.info(`PushToken registered successfully.`);
  })
  // ************* Register PushToken: end *************
}).catch((error: BusinessError) => {
  console.error(`Failed to get the PushToken. Error code: ${error.code}. Error message: ${error.message}`);
})

Registering the HarmonyOS Push Token is part of the SDK integration flow. For a complete code sample of the integration flow, see Complete SDK integration code sample.

Receive pushes

When you send a push through the HarmonyOS channel, the notification appears directly in the device's notification bar. The application detects the push behavior only when the user taps the notification to launch the application.

The process of retrieving push data from a notification is the same as for the Alibaba Cloud channel. For more information, see Get push data from a notification.