npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@react-native-ohos/react-native-push-notification

v8.1.3

Published

Local and Remote Notifications

Readme

文档模板:v0.4.2

本项目基于 react-native-push-notification 开发。

请到三方库的 Releases 发布地址查看配套的版本信息:

| 三方库名称 | 三方库版本(npm地址) | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | 源码地址 | | ------------ | ------------ | ------------------------------ | ------------- | ------------- |------------------------ | ------------- | ------------- | | @react-native-ohos/react-native-push-notification | ~8.1.3 (开发中) | Gitcode Releases | 0.72/0.77/0.82 | partially(0.72 / 0.82) | API12+ | 8.1.1 | master | | @react-native-ohos/react-native-push-notification | 8.1.2 | Gitcode Releases | 0.72/0.77 | 否 | API12+ | 8.1.1 | master |

简介

react-native-push-notification 工具库用于 React Native。 react-native-push-notification 是一个通知推送库,提供全面的通知管理功能。

下载安装

进入到工程目录并输入以下命令:

npm

npm install @react-native-ohos/react-native-push-notification

yarn

yarn add @react-native-ohos/react-native-push-notification

Link

| | 是否支持autolink | RN框架版本 | |-------|--------------|------------| | ~8.1.3 | partially(0.72/0.82) | 0.72/0.77/0.82 | | 8.1.2 | No | 0.72/0.77 |

使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/CPF-RN/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md

如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过ManualLink配置。

首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 harmony

1. Overrides RN SDK

为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 oh-package.json5 添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。

关于该字段的作用请阅读官方说明

{
  "overrides": {
    "@rnoh/react-native-openharmony": "^0.72.38" // ohpm 在线版本
    // "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // 指向本地 har 包的路径
    // "@rnoh/react-native-openharmony" : "./react_native_openharmony" // 指向源码路径
  }
}

2. 引入原生端代码

目前有两种方法:

  • 通过 har 包引入;
  • 直接链接源码。

方法一:通过 har 包引入(推荐)

[!TIP] har 包位于三方库安装路径的 harmony 文件夹下。

打开 entry/oh-package.json5,添加以下依赖

"dependencies": {
    "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
    "@react-native-ohos/react-native-push-notification": "file:../../node_modules/@react-native-ohos/react-native-push-notification/harmony/push_notification.har"
  }

点击右上角的 sync 按钮

或者在终端执行:

cd entry
ohpm install

方法二:直接链接源码

[!TIP] 如需使用直接链接源码,请参考直接链接源码说明

3. 配置 CMakeLists 和引入 PushNotificationPackage

打开 entry/src/main/cpp/CMakeLists.txt,添加:

project(rnapp)
cmake_minimum_required(VERSION 3.4.1)
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")

# RNOH_BEGIN: manual_package_linking_1
+ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-push-notification/src/main/cpp" ./push_notification)
# RNOH_END: manual_package_linking_1

# RNOH_BEGIN: manual_package_linking_2
+ target_link_libraries(rnoh_app PUBLIC rnoh_push_notification)
# RNOH_END: manual_package_linking_2

打开 entry/src/main/cpp/PackageProvider.cpp,添加:

#include "RNOH/PackageProvider.h"
#include "generated/RNOHGeneratedPackage.h"
+ #include "RTNPushNotificationPackage.h"

using namespace rnoh;

std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
    return {
        std::make_shared<RNOHGeneratedPackage>(ctx),
+       std::make_shared<RTNPushNotificationPackage>(ctx),
    };
}

4. 在 ArkTs 侧引入 PushNotificationPackage

打开 entry/src/main/ets/RNPackagesFactory.ts,添加:

import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts';
+ import { PushNotificationPackage } from '@react-native-ohos/react-native-push-notification/ts';

export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
  return [
+   new PushNotificationPackage(ctx)
  ];
}

运行

点击右上角的 sync 按钮

或者在命令行终端执行:

cd entry
ohpm install

然后编译、运行即可。

必要的配置项

[!TIP] 该模块的内容无法通过autolink自动生成,始终需要手动配置。

配置 EntryAbility(该模块始终需要手动配置)

HarmonyOS项目下 EntryAbility,一般位于 entry\src\main\ets\entryability\EntryAbility.ets

import {RNAbility} from '@rnoh/react-native-openharmony';
+ import { AbilityConstant, Want } from '@kit.AbilityKit';

export default class EntryAbility extends RNAbility {

+   onCreate(want: Want) {
+     super.onCreate(want)
+     this.saveNotificationWant(want);
+   }

  getPagePath() {
    return 'pages/Index';
  }

+  onNewWant(want: Want, _launchParam: AbilityConstant.LaunchParam): void {
+    this.saveNotificationWant(want);
+    if (want?.parameters?.['action_button_click']) {
+      setTimeout(() => {
+        this.context.eventHub.emit('onActionButtonClick', {});
+      }, 300);
+    }
+  }

+  private saveNotificationWant(want: Want) {
+    if (want?.parameters?.['notification_click'] || want?.parameters?.['action_button_click']) {
+      AppStorage.setOrCreate('PushNotificationWant', JSON.stringify(want));
+    }
+  }
}

约束与限制

兼容性

本文档内容基于以下版本验证通过:

  1. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
  2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio: 5.0.3.900; ROM: Next.0.0.71;
  3. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
  4. RNOH: 0.82.1; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;

权限要求

1.打开 entry/src/main/module.json5,添加相关配置

...
{
  "module": {
      "requestPermissions": [
+      {
+        "name": "ohos.permission.NOTIFICATION_CONTROLLER",
+        "reason": "$string:notification_controller_reason",
+        "usedScene": {
+          "abilities": [
+            "EntryAbility"
+          ],
+          "when": "always"
+        }
+      }
    ]
  }
}

2.在 entry 目录下添加申请权限的原因

打开 entry/src/main/resources/base/element/string.json,添加:

...
{
  "string": [
+    {
+      "name": "notification_controller_reason",
+      "value": "notification controller reason"
+    }
  ]
}

使用示例

下面的代码展示了这个库的基本使用场景:

[!WARNING] 使用时 import 的库名不变。

import { View, Text, Button, Alert, ScrollView, StyleSheet } from 'react-native'
import PushNotification, {
  SlotType,
  NotificationType
} from '@react-native-ohos/react-native-push-notification'
const App = () => {
  const sendBasicNotification = async () => {
    try {
      if (!PushNotification) {
        showAlert('错误', 'PushNotification模块不可用');
        return;
      }
      const options = {
        title: '这是一条普通消息',
        text: '这是普通消息的内容',
        id: Date.now(),
        notificationType: NotificationType.TEXT,
        isFloatingIcon: true,
        sound: 'rawfile/sound.mp3',
        notificationSlotType: SlotType.SOCIAL_COMMUNICATION,
      };

      const id = await PushNotification.localNotification(JSON.stringify(options));
      if (id !== undefined) {
        console.info(`Basic notification sent with id: ${id}`);
        showAlert('成功', `通知已发送,ID: ${id}`);
      } else {
        console.error('Send basic notification failed');
        showAlert('失败', '发送通知失败');
      }
    } catch (error) {
      console.error('Send basic notification failed:', error);
      showAlert('异常', `发送通知异常: ${error}`);
    }
  }; 

  const showAlert = (title: string, message: string) => {
    Alert.alert(title, message)
  }

  return (
    <ScrollView style={styles.container}>
      <View style={styles.section}>
        <Text style={styles.sectionTitle}>示例代码</Text>
        <View style={styles.buttonContainer}>
          <Button title="发送基本通知" onPress={sendBasicNotification} />
        </View>
      </View>
    </ScrollView>
  )
}
const styles = StyleSheet.create({
  container: {
    width: '100%',
    height: '100%',
    padding: 20,
  },
  section: {
    marginBottom: 20,
    padding: 10,
    borderWidth: 1,
    borderColor: '#ccc',
    borderRadius: 5,
  },
  sectionTitle: {
    fontSize: 18,
    fontWeight: 'bold',
    marginBottom: 10,
  },
  buttonContainer: {
    marginVertical: 5,
  }
})

[!TIP] 若示例中使用了 sound: 'rawfile/sound.mp3',请将音频资源放置到 entry/src/main/resources/rawfile/ 目录下。

接口说明

API

[!TIP] "Platform"列表示该属性在原三方库上支持的平台。

[!TIP] "OpenHarmony Support"列为 yes 表示 OpenHarmony平台支持 该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。

| 名称 | 类型 | 参数类型 | 返回值 | 必填 | 平台 | OpenHarmony平台支持 | Description | |---------------------------------|:--------:|-----------------------|-------|----|-------------|-----------------|-----------------| | configure | function | Object | Promise<void> | No | iOS/Android | Yes | 配置通知 | | unregister | function | / | void | No | iOS/Android | Yes | 注销通知监听器 | | localNotification | function | string | Promise<number | undefined> | No | iOS/Android | Yes | 显示本地通知 | | localNotificationSchedule | function | string | Promise<number | undefined> | No | iOS/Android | Yes | 调度本地通知 | | requestPermissions | function | / | Promise<boolean> | No | iOS/Android | Yes | 请求通知权限 | | subscribeToTopic | function | string | Promise<boolean> | No | Android | No | 订阅Firebase主题 | | unsubscribeFromTopic | function | string | Promise<boolean> | No | Android | No | 取消订阅Firebase主题 | | presentLocalNotification | function | string | Promise<null | number> | No | iOS/Android | Yes | 展示本地通知 | | scheduleLocalNotification | function | string | Promise<null | number> | No | Android | No | 调度本地通知(Android) | | cancelLocalNotifications | function | userInfo: any | any | No | 已弃用 | No | 取消本地通知 | | cancelLocalNotification | function | number | Promise<boolean> | Yes | iOS/Android | Yes | 取消本地通知 | | clearLocalNotification | function | number | Promise<boolean> | Yes | iOS/Android | Yes | 清除本地通知 | | cancelAllLocalNotifications | function | / | Promise<boolean> | No | iOS/Android | Yes | 取消所有本地通知 | | setApplicationIconBadgeNumber | function | number | Promise<boolean> | Yes | iOS/Android | Yes | 设置应用图标徽章数字 | | getApplicationIconBadgeNumber | function | / | Promise<number> | No | iOS/Android | Yes | 获取应用图标徽章数字 | | popInitialNotification | function | Object | Promise<void> | No | iOS/Android | Yes | 获取初始通知 | | checkPermissions | function | / | Promise<boolean> | No | iOS/Android | Yes | 检查通知权限 | | abandonPermissions | function | / | Promise<void> | No | iOS/Android | Yes | 放弃通知权限 | | clearAllNotifications | function | / | Promise<void> | No | iOS/Android | Yes | 清除所有通知 | | removeAllDeliveredNotifications | function | / | Promise<void> | No | iOS/Android | Yes | 移除所有已送达的通知 | | getDeliveredNotifications | function | / | Promise<string> | No | iOS/Android | Yes | 获取已发送通知列表 | | getScheduledLocalNotifications | function | / | Promise<string> | No | iOS/Android | Yes | 获取计划通知列表 | | removeDeliveredNotifications | function | number | Promise<void> | Yes | iOS/Android | Yes | 移除指定已发送通知 | | invokeApp | function | string | Promise<void> | Yes | iOS/Android | Yes | 启动应用 | | getChannels | function | / | Promise<string> | No | iOS/Android | Yes | 获取通知渠道列表 | | channelExists | function | notificationType: SlotType | Promise<boolean> | Yes | iOS/Android | Yes | 检查通知渠道是否存在 | | createChannel | function | channelType: SlotType | Promise<boolean> | Yes | iOS/Android | Yes | 创建通知渠道 | | channelBlocked | function | channelType: SlotType | Promise<boolean> | Yes | iOS/Android | Yes | 检查指定类型的渠道是否被阻 | | deleteChannel | function | type: SlotType | Promise<boolean> | Yes | iOS/Android | Yes | 删除通知渠道 | | setNotificationCategories | function | / | any | No | iOS | No | 设置通知类别(iOS) |

类型定义

SlotType 类型列表

| Name | Description | Type | Required | Platform | HarmonyOS Support | |------|-------------|------|----------|----------|-------------------| | UNKNOWN_TYPE | 未知类型 | number | No | HarmonyOS | Yes | | SOCIAL_COMMUNICATION | 社交通讯 | number | No | HarmonyOS | Yes | | SERVICE_INFORMATION | 服务信息 | number | No | HarmonyOS | Yes | | CONTENT_INFORMATION | 内容信息 | number | No | HarmonyOS | Yes | | LIVE_VIEW | 实况视图 | number | No | HarmonyOS | Yes | | CUSTOMER_SERVICE | 客户服务 | number | No | HarmonyOS | Yes | | OTHER_TYPES | 其他类型 | number | No | HarmonyOS | Yes |

遗留问题

其他

目录结构

/react-native-push-notification  # 项目根目录
├── harmony              # 鸿蒙适配代码
│    ├─ push_notification.har          # har包
│    └─ push_notification                  # 鸿蒙适配核心代码
│          ├─ Index.ets    # 鸿蒙适配代码入口
│          └─ src/main/ets
│              ├─ PushNotificationPackage.ets  # push_notification包封装
│              ├─ PushNotificationModule.ets   # 原生模块实现
│              ├─ RNPackagesFactory.ets        # RN 包工厂
│              ├─ Types/
│              │    ├─ TypeClass.ets           # 类型定义
│              │    └─ Types.ets               # 类型导出
│              ├─ generated/                   # 自动生成代码
│              │    ├─ components/
│              │    ├─ turboModules/
│              │    └─ index.ets
│              ├─ pages/
│              │    └─ Index.ets
│              ├─ pushnotification/            # 通知业务实现
│              │    ├─ AuthorizeNotificationHelper.ets
│              │    ├─ ChannelHelper.ets
│              │    ├─ HarmonyNotificationManager.ets
│              │    ├─ HarmonyPushNotification.ets
│              │    ├─ LocalNotificationHeloper.ets
│              │    ├─ PushNotification.ets
│              │    ├─ RemotepushKit.ets
│              │    ├─ RepeatingNotificationScheduler.ets
│              │    └─ ScheduledNotificationHelper.ets
│              └─ util/                        # 工具类
│                   ├─ NotificationImage.ets
│                   └─ utils.ets
├── src                  # RN代码
│    └─ NativePushNotification.ts  # 入口文件
├── README_en.md           # 英文安装使用方法
└── README.md              # 中文安装使用方法

贡献代码

使用过程中发现任何问题都可以提交 Issue,当然,也非常欢迎提交 PR

开源协议

本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。