HarmonyOS

操作步骤

步骤1:集成 TIMPush

// For the version number "VERSION", please refer to the changelog for configuration.
// Configure the integration package in oh-package.json5
dependencies: {
"@tencentcloud/timpush": "^VERSION",
"@tencentcloud/imsdk": "^VERSION",
}

步骤2:注册推送

调用接口推送注册成功后,就可以收到离线推送通知了。
import { TIMPushListener, TIMPushManager, TIMPushMessage } from '@tencentcloud/timpush';

TIMPushManager.getInstance()
.registerPush(context, your sdkAppId, "client secret", Chat console certificate ID)
.then((result) => {
HiLog("registerPush success:", result.message);
})
.catch((error: Error) => {
HiLog("registerPush failed", error.code, error.message);
})

步骤3:消息触达统计配置

如果您需要统计触达数据,请按照如下完成配置:

回执地址:https://api.im.qcloud.com/v3/offline_push_report/harmony

步骤4:发送推送消息

接口详细说明可参见:REST API 接口-发起全员/标签推送

步骤5:解析离线推送消息

收到推送消息后点击通知栏,组件会回调该点击事件和透传离线消息。
注意:
注册回调时机建议放在应用 UIAbility 的 onCreate() 函数中。
控制台配置点击后续动作按如下配置,选择打开应用内指定界面,请勿修改默认值并直接使用默认值。

let pushListener: TIMPushListener = {
onNotificationClicked: (data) => {
HiLog("onNotificationClicked", data);
}
}

TIMPushManager.getInstance().addPushListener(pushListener);
恭喜您已经完成了推送插件的接入,需要提醒您:推送插件试用或购买到期后,将自动停止提供推送服务(包括普通消息离线推送、全员/标签推送等服务)。为避免影响您的业务正常使用,请提前购买/续费
说明:
接入完成收不到推送,请先自助使用 排查工具 查看下具体原因。推送指标数据查看,请使用 数据统计 查询。
全员/标签推送功能请参见:REST API 接口 - 发起全员/标签推送