# Push

# uni-push

# 配置依赖

统一推送服务依赖此ohpm包:@uni_modules/uni-push@1.0.1

oh-package.json5文件内dependencies字段下添加如下内容:

"@uni_modules/uni-push": "1.0.1"

# 配置参数

在项目模块级别下的src/main/module.json5文件中,新增metadata并配置GETUI_APPIDclient_id,如下所示:

{
  "module": {
     "metadata": [
      {
        "name": "GETUI_APPID",
        "value": "AppID信息"
      },
      {
        "name": "client_id",
        "value": "在华为"
      }
     ]
  }
}

# 注册模块

在uni_modules入口文件index.generated.ets内注册uni-push api。

import { uni } from "@dcloudio/uni-app-runtime";
import { getPushClientId,onPushMessage,offPushMessage,createPushMessage,setAppBadgeNumber } from '@uni_modules/uni-push'

export function initUniModules() {
  initUniExtApi();
}

function initUniExtApi() {
  uni.getPushClientId = getPushClientId
  uni.onPushMessage = onPushMessage
  uni.offPushMessage = offPushMessage
  uni.createPushMessage = createPushMessage
  uni.setAppBadgeNumber = setAppBadgeNumber
}