From cf895ca8c62a4894a84afe978fe5811c5d1915fe Mon Sep 17 00:00:00 2001 From: qinjianqi Date: Mon, 16 Dec 2024 15:19:45 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20[Issues:=20#IBB50S]=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9@react-native-community/push-notification-ios=E6=8C=87?= =?UTF-8?q?=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...-native-community-push-notification-ios.md | 105 +++++++---------- ...-native-community-push-notification-ios.md | 109 +++++++----------- 2 files changed, 81 insertions(+), 133 deletions(-) diff --git a/en/react-native-community-push-notification-ios.md b/en/react-native-community-push-notification-ios.md index b82cfe30..9ccfde4c 100644 --- a/en/react-native-community-push-notification-ios.md +++ b/en/react-native-community-push-notification-ios.md @@ -1,40 +1,35 @@ -> Template version: v0.2.2 +> Template version: v0.3.0

@react-native-community/push-notification-ios

-

- - Supported platforms - - - License - -

-> [!TIP] [GitHub address](https://github.com/react-native-oh-library/react-native-push-notification-ios) +This project is based on [@react-native-community/push-notification-ios@1.11.0](https://github.com/react-native-push-notification/ios)。 -## Installation and Usage +This third-party library has been migrated to Gitee and is now available for direct download from npm, the new package name is: `@react-native-ohos/push-notification-ios`, The version correspondence details are as follows: -Find the matching version information in the release address of a third-party library: [@react-native-oh-tpl/push-notification-ios Releases](https://github.com/react-native-oh-library/react-native-push-notification-ios/releases).For older versions that are not published to npm, please refer to the [installation guide](/en/tgz-usage-en.md) to install the tgz package. - -Go to the project directory and execute the following instruction: +| Version | Package Name | Repository | Release | +|----------------------------| ------------------------------------------------- | ------------------ | -------------------------- | +| <= 1.11.0-0.1.3@deprecated | @react-native-oh-tpl/push-notification-ios | [Github(deprecated)](https://github.com/react-native-oh-library/react-native-push-notification-ios) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-push-notification-ios/releases) | +| > 1.11.0 | @react-native-ohos/push-notification-ios | [Gitee](https://gitee.com/openharmony-sig/rntpc_ios) | [Gitee Releases](https://gitee.com/openharmony-sig/rntpc_ios/releases) | +## 1. Installation and Usage +Go to the project directory and execute the following instruction: #### **npm** ```bash -npm install @react-native-oh-tpl/push-notification-ios +npm install @react-native-ohos/push-notification-ios ``` #### **yarn** ```bash -yarn add @react-native-oh-tpl/push-notification-ios +yarn add @react-native-ohos/push-notification-ios ``` @@ -167,27 +162,35 @@ export const App = () => { }; ``` -## Link +## 2. Manual Link -Currently, HarmonyOS does not support AutoLink. Therefore, you need to manually configure the linking. +This step provides guidance for manually configuring native dependencies. Open the `harmony` directory of the HarmonyOS project in DevEco Studio. -### 1. Adding the overrides Field to oh-package.json5 File in the Root Directory of the Project +### 2.1. Overrides RN SDK + +To ensure the project relies on the same version of the RN SDK, you need to add an `overrides` field in the project's root `oh-package.json5` file, specifying the RN SDK version to be used. The replacement version can be a specific version number, a semver range, or a locally available HAR package or source directory. + +For more information about the purpose of this field, please refer to the [official documentation](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#en-us_topic_0000001792256137_overrides). ```json { - ... "overrides": { - "@rnoh/react-native-openharmony" : "./react_native_openharmony" + "@rnoh/react-native-openharmony": "^0.72.38" // ohpm version + // "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // a locally available HAR package + // "@rnoh/react-native-openharmony" : "./react_native_openharmony" // source code directory } } ``` -### 2. Introducing Native Code +### 2.2. Introducing Native Code Currently, two methods are available: +- Use the HAR file. +- Directly link to the source code。 + Method 1 (recommended): Use the HAR file. > [!TIP] The HAR file is stored in the `harmony` directory in the installation path of the third-party library. @@ -196,9 +199,7 @@ Open `entry/oh-package.json5` file and add the following dependencies: ```json "dependencies": { - "@rnoh/react-native-openharmony": "file:../react_native_openharmony", - - "@react-native-oh-tpl/push-notification-ios": "file:../../node_modules/@react-native-oh-tpl/push-notification-ios/harmony/push_notification.har" + "@react-native-ohos/push-notification-ios": "file:../../node_modules/@react-native-ohos/push-notification-ios/harmony/push_notification.har" } ``` @@ -215,42 +216,18 @@ Method 2: Directly link to the source code. > [!TIP] For details, see [Directly Linking Source Code](/en/link-source-code.md). -### 3. Configuring CMakeLists and Introducing PushNotificationPackage +### 2.3. Configuring CMakeLists and Introducing PushNotificationPackage Open `entry/src/main/cpp/CMakeLists.txt` and add the following code: ```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/push-notification-ios/src/main/cpp" ./push_notification) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/push-notification-ios/src/main/cpp" ./push_notification) # 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 ``` @@ -272,13 +249,13 @@ std::vector> PackageProvider::getPackages(Package::Cont } ``` -### 4.Introducing PushNotificationPackage to ArkTS +### 2.4. Introducing PushNotificationPackage to ArkTS Open the `entry/src/main/ets/RNPackagesFactory.ts` file and add the following code: ```diff ... -+ import { PushNotificationPackage } from '@react-native-oh-tpl/push-notification-ios/ts'; ++ import { PushNotificationPackage } from '@react-native-ohos/push-notification-ios/ts'; export function createRNPackages(ctx: RNPackageContext): RNPackage[] { return [ @@ -288,7 +265,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { } ``` -### 5.Running +### 2.5. Running Click the `sync` button in the upper right corner. @@ -301,16 +278,14 @@ ohpm install Then build and run the code. -## Constraints - -### Compatibility +## 3. Constraints -To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone. +### 3.1. Compatibility -Check the release version information in the release address of the third-party library: [@react-native-oh-tpl/push-notification-ios Releases](https://github.com/react-native-oh-library/react-native-push-notification-ios/releases) +Check the release version information in the release address of the third-party library: [@react-native-ohos/push-notification-ios Releases](https://gitee.com/openharmony-sig/rntpc_ios/releases) -## APIs +## 4. APIs > [!TIP] The **Platform** column indicates the platform where the properties are supported in the original third-party library. @@ -331,7 +306,7 @@ Check the release version information in the release address of the third-party | getInitialNotification | This method returns a promise. If the app was launched by a push notification, this promise resolves to an object of type PushNotificationIOS. Otherwise, it resolves to null. | function | no | iOS | no | | getScheduledLocalNotifications | Gets the local notifications that are currently scheduled | function | no | iOS | no | -## Properties +## 5. Properties > [!TIP] The **Platform** column indicates the platform where the properties are supported in the original third-party library. @@ -360,13 +335,13 @@ _NotificationRequest:_ | `isTimeZoneAgnostic` | If true, fireDate adjusted automatically upon time zone changes (e.g. for an alarm clock) | boolean | no | All | no | | `interruptionLevel` | A string specifying the interruption level. Valid values are `'active'`, `'passive'`, `'timeSensitive'`, or `'critical'` | string | no | All | no | -## Known Issues +## 6. Known Issues - [ ] HarmonyOS 的 NotificationManager 的规格和 IOS 不一致,其 NotificationRequest 所含参数,在 HarmonyOS 上部分没有适配对应参数,问题: [issue#1](https://github.com/react-native-oh-library/react-native-push-notification-ios/issues/4) - [ ] 原库部分接口在 HarmonyOS 中没有对应接口处理相关逻辑,问题: [issue#2](https://github.com/react-native-oh-library/react-native-push-notification-ios/issues/3) -## Others +## 7. Others -## License +## 8. License -This project is licensed under [The MIT License (MIT)](https://github.com/react-native-push-notification/ios/blob/master/LICENSE). +This project is licensed under [The MIT License (MIT)](https://gitee.com/openharmony-sig/rntpc_ios/blob/master/LICENSE). diff --git a/zh-cn/react-native-community-push-notification-ios.md b/zh-cn/react-native-community-push-notification-ios.md index b3129b52..96dc5e74 100644 --- a/zh-cn/react-native-community-push-notification-ios.md +++ b/zh-cn/react-native-community-push-notification-ios.md @@ -1,23 +1,19 @@ -> 模板版本:v0.2.2 +> 模板版本:v0.3.0

@react-native-community/push-notification-ios

-

- - Supported platforms - - - License - -

+本项目基于 [@react-native-community/push-notification-ios@1.11.0](https://github.com/react-native-push-notification/ios) 开发。 -> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-push-notification-ios) +该第三方库的仓库已迁移至 Gitee,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/push-notification-ios`,具体版本所属关系如下: -## 安装与使用 +| Version | Package Name | Repository | Release | +|----------------------------| ------------------------------------------------- | ------------------ | -------------------------- | +| <= 1.11.0-0.1.3@deprecated | @react-native-oh-tpl/push-notification-ios | [Github(deprecated)](https://github.com/react-native-oh-library/react-native-push-notification-ios) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-push-notification-ios/releases) | +| > 1.11.0 | @react-native-ohos/push-notification-ios | [Gitee](https://gitee.com/openharmony-sig/rntpc_ios) | [Gitee Releases](https://gitee.com/openharmony-sig/rntpc_ios/releases) | -请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/push-notification-ios Releases](https://github.com/react-native-oh-library/react-native-push-notification-ios/releases) 。对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 +## 1. 安装与使用 进入到工程目录并输入以下命令: @@ -26,13 +22,13 @@ #### **npm** ```bash -npm install @react-native-oh-tpl/push-notification-ios +npm install @react-native-ohos/push-notification-ios ``` #### **yarn** ```bash -yarn add @react-native-oh-tpl/push-notification-ios +yarn add @react-native-ohos/push-notification-ios ``` @@ -165,29 +161,34 @@ export const App = () => { }; ``` -## Link +## 2. Manual Link + +此步骤为手动配置原生依赖项的指导。 + +首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`。 -目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。 +### 2.1. Overrides RN SDK -首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony` +为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 `oh-package.json5` 添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。 -### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段 +关于该字段的作用请阅读[官方说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#zh-cn_topic_0000001792256137_overrides) ```json { - ... "overrides": { - "@rnoh/react-native-openharmony" : "./react_native_openharmony" + "@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.引入原生端代码 +### 2.2. 引入原生端代码 目前有两种方法: -1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); -2. 直接链接源码。 +- 通过 har 包引入; +- 直接链接源码。 方法一:通过 har 包引入(推荐) @@ -197,15 +198,13 @@ export const App = () => { ```json "dependencies": { - "@rnoh/react-native-openharmony": "file:../react_native_openharmony", - - "@react-native-oh-tpl/push-notification-ios": "file:../../node_modules/@react-native-oh-tpl/push-notification-ios/harmony/push_notification.har" + "@react-native-ohos/push-notification-ios": "file:../../node_modules/@react-native-ohos/push-notification-ios/harmony/push_notification.har" } ``` 点击右上角的 `sync` 按钮 -或者在终端执行: +或者在命令行终端执行: ```bash cd entry @@ -216,41 +215,18 @@ ohpm install > [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) -### 3.配置 CMakeLists 和引入 PushNotificationPackage +### 2.3. 配置 CMakeLists 和引入 PushNotificationPackage 打开 `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/push-notification-ios/src/main/cpp" ./push_notification) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/push-notification-ios/src/main/cpp" ./push_notification) # 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 ``` @@ -272,13 +248,13 @@ std::vector> PackageProvider::getPackages(Package::Cont } ``` -### 4.在 ArkTs 侧引入 PushNotificationPackage +### 2.4. 在 ArkTs 侧引入 PushNotificationPackage 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: ```diff ... -+ import { PushNotificationPackage } from '@react-native-oh-tpl/push-notification-ios/ts'; ++ import { PushNotificationPackage } from '@react-native-ohos/push-notification-ios/ts'; export function createRNPackages(ctx: RNPackageContext): RNPackage[] { return [ @@ -288,7 +264,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { } ``` -### 5.运行 +### 2.5. 运行 点击右上角的 `sync` 按钮 @@ -301,16 +277,13 @@ ohpm install 然后编译、运行即可。 -## 约束与限制 - -### 兼容性 - -要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 +## 3. 约束与限制 -请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/push-notification-ios Releases](https://github.com/react-native-oh-library/react-native-push-notification-ios/releases) +### 3.1. 兼容性 +请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-ohos/push-notification-ios Releases](https://gitee.com/openharmony-sig/rntpc_ios/releases) -## API +## 4. API > [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 @@ -331,7 +304,7 @@ ohpm install | getInitialNotification | This method returns a promise. If the app was launched by a push notification, this promise resolves to an object of type PushNotificationIOS. Otherwise, it resolves to null. | function | no | iOS | no | | getScheduledLocalNotifications | Gets the local notifications that are currently scheduled | function | no | iOS | no | -## 属性 +## 5. 属性 > [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 @@ -361,13 +334,13 @@ _NotificationRequest:_ | `isTimeZoneAgnostic` | If true, fireDate adjusted automatically upon time zone changes (e.g. for an alarm clock) | boolean | no | All | no | | `interruptionLevel` | A string specifying the interruption level. Valid values are `'active'`, `'passive'`, `'timeSensitive'`, or `'critical'` | string | no | All | no | -## 遗留问题 +## 6. 遗留问题 - [ ] HarmonyOS 的 NotificationManager 的规格和 IOS 不一致,其 NotificationRequest 所含参数,在 HarmonyOS 上部分没有适配对应参数,问题: [issue#1](https://github.com/react-native-oh-library/react-native-push-notification-ios/issues/4) - [ ] 原库部分接口在 HarmonyOS 中没有对应接口处理相关逻辑,问题: [issue#2](https://github.com/react-native-oh-library/react-native-push-notification-ios/issues/3) -## 其他 +## 7. 其他 -## 开源协议 +## 8. 开源协议 -本项目基于 [The MIT License (MIT)](https://github.com/react-native-push-notification/ios/blob/master/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file +本项目基于 [The MIT License (MIT)](https://gitee.com/openharmony-sig/rntpc_ios/blob/master/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file -- Gitee