# react-native-push-notification-pack **Repository Path**: cbbgs/react-native-push-notification-pack ## Basic Information - **Project Name**: react-native-push-notification-pack - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-12-18 - **Last Updated**: 2026-01-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # React Native Push Notification React Native 推送通知库,提供全面的通知管理功能。 ## 下载和使用 ### npm ```bash npm install @react-native-oh-tpl/react-native-push-notification ``` ### yarn ```bash yarn add @react-native-oh-tpl/react-native-push-notification ``` 下面的代码展示了这个库的基本使用场景: 使用时 import 的库名不变。 ```jsx import PushNotification from '@react-native-oh-tpl/react-native-push-notification'; 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}`); } }; ``` #### ## Link | | 是否支持autolink | RN框架版本 | | -------------------------- | ------------ | ------ | | ~8.7.0 | No | 0.77 | | ~8.6.4 | Yes | 0.72 | | <= 8.6.3-0.4.17@deprecated | No | 0.72 | 使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:[https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md](https://gitee.com/link?target=https%3A%2F%2Fgitcode.com%2Fopenharmony-sig%2Fohos_react_native%2Fblob%2Fmaster%2Fdocs%2Fzh-cn%2FAutolinking.md) 使用 AutoLink 的工程需要根据该文档配置,Autolink 框架指导文档: https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md 如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过ManualLink配置。
ManualLink: 此步骤为手动配置原生依赖项的指导 首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`。 ### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段 ```json { ... "overrides": { "@rnoh/react-native-openharmony" : "./react_native_openharmony" } } ``` ### 2.引入原生端代码 目前有两种方法: 1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); 2. 直接链接源码。 方法一:通过 har 包引入(推荐) > [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 打开 `entry/oh-package.json5`,添加以下依赖 ```json "dependencies": { "@rnoh/react-native-openharmony": "file:../react_native_openharmony", "@react-native-ohos/react-native-fast-image": "file:../../node_modules/@react-native-oh-tpl/react-native-push-notification/harmony/push_notification.har" } ``` 点击右上角的 `sync` 按钮 或者在终端执行: ```bash cd entry ohpm install ``` 方法二:直接链接源码 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) ### 3.配置 CMakeLists 和引入 PushNotificationPackage > 若使用的是 <= 8.6.3-0.4.17 版本,请跳过本章。 打开 `entry/src/main/cpp/CMakeLists.txt`,添加: ```diff project(rnapp) cmake_minimum_required(VERSION 3.4.1) set(CMAKE_SKIP_BUILD_RPATH TRUE) set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") + set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") set(LOG_VERBOSITY_LEVEL 1) set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use add_compile_definitions(WITH_HITRACE_SYSTRACE) add_subdirectory("${RNOH_CPP_DIR}" ./rn) # RNOH_BEGIN: manual_package_linking_1 add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) + add_subdirectory("${OH_MODULES}/@react-native-oh-tpl/react-native-push-notification/src/main/cpp" ./fast-image) # RNOH_END: manual_package_linking_1 file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") add_library(rnoh_app SHARED ${GENERATED_CPP_FILES} "./PackageProvider.cpp" "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" ) target_link_libraries(rnoh_app PUBLIC rnoh) # RNOH_BEGIN: manual_package_linking_2 target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) + target_link_libraries(rnoh_app PUBLIC rnoh_push_notification) # RNOH_END: manual_package_linking_2 ``` 打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: ```diff #include "RNOH/PackageProvider.h" #include "generated/RNOHGeneratedPackage.h" #include "SamplePackage.h" + #include "RTNPushNotificationPackage.h" using namespace rnoh; std::vector> PackageProvider::getPackages(Package::Context ctx) { return { std::make_shared(ctx), std::make_shared(ctx), + std::make_shared(ctx), }; } ``` ### 4.在 ArkTs 侧引入 PushNotificationPackage 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: ```diff ... + import {PushNotificationPackage} from '@react-native-oh-tpl/react-native-push-notification/ts'; export function createRNPackages(ctx: RNPackageContext): RNPackage[] { return [ new SamplePackage(ctx), + new FastImagePackage(ctx) ]; } ```
#### 运行 点击右上角的 `sync` 按钮 或者在终端执行: ```bash cd entry ohpm install ``` 然后编译、运行即可。 ## 约束与限制 ### 兼容性 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 在以下版本验证通过: 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; ## 属性 ### NotificationOptions - `id`: 通知ID - `showDeliveryTime`: 是否显示分发时间 - `tapDismissed`: 通知是否自动清除 - `autoDeletedTime`: 自动清除的时间 - `wantAgent`: WantAgent封装了应用的行为意图,点击通知时触发该行为 - `extraInfo`: 扩展参数 - `isAlertOnce`: 设置是否仅有一次此通知提醒 - `isStopwatch`: 是否显示已用时间 - `isCountDown`: 是否显示倒计时时间 - `isFloatingIcon`: 是否显示状态栏图标 - `label`: 通知标签 - `smallIcon`: 小图标(Base64编码或资源路径) - `largeIcon`: 大图标(Base64编码或资源路径) - `lockscreenPicture`: 锁屏界面显示的图片 - `notificationType`: 通知类型(TEXT, LONGTEXT, LINES, PICTURE, PROGRESS) - `title`: 通知标题 - `text`: 通知内容 - `additionalText`: 通知附加内容 - `briefText`: 通知概要内容 - `longText`: 通知的长文本 - `expandedTitle`: 通知展开时的标题 - `picture`: 图片通知的图片(Base64编码或资源路径) - `fileName`: 下载文件名(进度条通知) - `progressValue`: 下载进度(进度条通知) - `fireDate`: 计划通知触发时间 - `actionButtons`: 通知按钮数组 - `groupName`: 组通知名称 - `notificationSlotType`: 通知渠道类型 - `repeatType`: 重复类型(minute, hour, day, week, month, time) - `repeatTime`: 重复间隔时间 - `repeatInterval`: 重复间隔(毫秒) - `repeatCount`: 重复次数(-1表示无限重复) ### NotificationType 枚举 - `TEXT`: 基本文本通知 - `LONGTEXT`: 长文本通知 - `LINES`: 多行文本通知 - `PICTURE`: 图片通知 - `PROGRESS`: 进度条通知 ### SlotType 枚举 - `UNKNOWN_TYPE`: 未知类型 - `SOCIAL_COMMUNICATION`: 社交通讯 - `SERVICE_INFORMATION`: 服务信息 - `CONTENT_INFORMATION`: 内容信息 - `LIVE_VIEW`: 直播观看 - `CUSTOMER_SERVICE`: 客户服务 - `OTHER_TYPES`: 其他类型 ### SlotLevel 枚举 - `LEVEL_NONE`: 无级别 - `LEVEL_MIN`: 最低级别 - `LEVEL_LOW`: 低级别 - `LEVEL_DEFAULT`: 默认级别 - `LEVEL_HIGH`: 高级别 ## 静态方法 | 方法名 | 描述 | 参数 | | ------------------------------- | -------------- | ------------------------------------------- | | configure | 配置推送通知服务 | options: (config: string) => void | | localNotification | 发送本地通知 | details: string | | cancelLocalNotification | 取消指定ID的本地通知 | notificationId: number | | cancelAllLocalNotifications | 取消所有本地通知 | 无 | | setApplicationIconBadgeNumber | 设置应用图标徽章数字 | number: number | | getApplicationIconBadgeNumber | 获取应用图标徽章数字 | 无 | | clearBadge | 清除徽章 | 无 | | clearAllNotifications | 清除所有通知 | 无 | | removeAllDeliveredNotifications | 移除所有已送达的通知 | 无 | | getDeliveredNotifications | 获取已送达的通知列表 | 无 | | getScheduledLocalNotifications | 获取计划中的本地通知 | 无 | | removeDeliveredNotifications | 移除指定ID的已送达通知 | id: number | | getChannels | 获取通知渠道列表 | 无 | | channelExists | 检查指定类型的渠道是否存在 | notificationType: SlotType | | createChannel | 创建通知渠道 | channelType: SlotType | | channelBlocked | 检查指定类型的渠道是否被阻止 | channelType: SlotType | | deleteChannel | 删除通知渠道 | type: SlotType | | requestPermissions | 请求通知权限 | 无 | | checkPermissions | 检查通知权限状态 | 无 | | openNotifictionSetting | 打开通知设置页面 | 无 | | unregister | 注销推送服务 | 无 | | isConfigured | 检查是否已配置 | 无 | | popInitialNotification | 弹出初始通知 | want: Object | | createWantAgent | 创建WantAgent | notificationId: number, actionType?: string | | registerActionButton | 注册通知按钮动作 | actionId: string, action: () => void | | getPushToken | 获取推送令牌 | 无 | ## 开源协议 本项目基于 [The MIT License (MIT)](https://gitee.com/link?target=https%3A%2F%2Fgithub.com%2FDylanVann%2Freact-native-fast-image%2Fblob%2Fmain%2FLICENSE) ,请自由地享受和参与开源。