From 6532bc2cb586b7d3a6d19ad89c4099e29dd8ef61 Mon Sep 17 00:00:00 2001
From: panyinan
Date: Wed, 7 Feb 2024 10:19:51 +0800
Subject: [PATCH] =?UTF-8?q?[Issues:=20#I91C0R]=20=E6=B7=BB=E5=8A=A0react-n?=
=?UTF-8?q?ative-community-push-notification-ios=E6=8C=87=E5=AF=BC?=
=?UTF-8?q?=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 | 377 ++++++++++++++++++
1 file changed, 377 insertions(+)
create mode 100644 1224/react-native-community-push-notification-ios.md
diff --git a/1224/react-native-community-push-notification-ios.md b/1224/react-native-community-push-notification-ios.md
new file mode 100644
index 00000000..17dbcf71
--- /dev/null
+++ b/1224/react-native-community-push-notification-ios.md
@@ -0,0 +1,377 @@
+> 模板版本:v0.1.3
+
+
+
@react-native-community/push-notification-ios
+
+
+
+
+
+
+
+
+
+
+> [!TIP] [Github 地址](https://github.com/react-native-push-notification/ios)
+
+## 安装与使用
+
+进入到工程目录并输入以下命令:
+
+
+#### **npm**
+
+```bash
+npm install @react-native-oh-tpl/push-notification-ios@file:#
+```
+
+#### **yarn**
+
+```bash
+yarn add @react-native-oh-tpl/push-notification-ios@file:#
+```
+
+
+
+
+下面的代码展示了这个库的基本使用场景:
+
+>[!WARNING] 使用时 import 的库名不变。
+
+```js
+import React, { useState } from 'react';
+import {
+ View,
+ Text,
+ Button
+} from 'react-native';
+
+import PushNotification from '@react-native-community/push-notification-ios';
+
+export const App = () => {
+
+ const [data, setData] = useState({});
+
+ const addNotificationRequest = () => {
+ PushNotification.addNotificationRequest({
+ id: 'test',
+ title: 'title',
+ subtitle: 'subtitle',
+ body: 'body',
+ category: 'test',
+ threadId: 'thread-id',
+ fireDate: new Date(new Date().valueOf() + 2000),
+ repeats: true,
+ userInfo: {
+ image: 'https://www.github.com/Naturalclar.png',
+ }
+ });
+ };
+
+ const addSilentNotificationRequest = () => {
+ PushNotification.addNotificationRequest({
+ id: 'test-4',
+ title: 'title',
+ subtitle: 'subtitle',
+ body: 'body',
+ category: 'test',
+ isSilent: true,
+ threadId: 'thread-id',
+ fireDate: new Date(new Date().valueOf() + 2000),
+ repeats: true,
+ userInfo: {
+ image: 'https://www.github.com/Naturalclar.png',
+ }
+ });
+ };
+
+ const addMultipleRequests = () => {
+ PushNotification.addNotificationRequest({
+ id: 'test-1',
+ title: 'First',
+ subtitle: 'subtitle',
+ body: 'First Notification out of 3',
+ category: 'test',
+ threadId: 'thread-id',
+ fireDate: new Date(new Date().valueOf() + 10000),
+ repeats: true,
+ });
+
+ PushNotification.addNotificationRequest({
+ id: 'test-2',
+ title: 'Second',
+ subtitle: 'subtitle',
+ body: 'Second Notification out of 3',
+ category: 'test',
+ threadId: 'thread-id',
+ fireDate: new Date(new Date().valueOf() + 12000),
+ repeats: true,
+ });
+
+ PushNotification.addNotificationRequest({
+ id: 'test-3',
+ title: 'Third',
+ subtitle: 'subtitle',
+ body: 'Third Notification out of 3',
+ category: 'test',
+ threadId: 'thread-id',
+ fireDate: new Date(new Date().valueOf() + 14000),
+ repeats: true,
+ });
+ };
+
+ const removeAllDeliveredNotifications = () => {
+ PushNotification.removeAllDeliveredNotifications();
+ };
+
+ const removeDeliveredNotifications = () => {
+ PushNotification.removeDeliveredNotifications(['test-1', 'test-2']);
+ };
+
+ const getDeliveredNotifications = () => {
+ PushNotification.getDeliveredNotifications((data) => {
+ if (data) {
+ setData(data)
+ } else {
+ console.log("failed");
+ }
+ });
+ };
+
+
+ return (
+
+
+
+
+
+ );
+};
+
+
+```
+## Link
+
+目前鸿蒙暂不支持 AutoLink,所以 Link 步骤需要手动配置。
+
+首先需要使用 DevEco Studio 打开项目里的鸿蒙工程 `harmony`
+
+### 引入原生端代码
+
+目前有两种方法:
+
+1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
+2. 直接链接源码。
+
+方法一:通过 har 包引入
+
+> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
+
+打开 `entry/oh-package.json5`,添加以下依赖
+
+```json
+"dependencies": {
+ "rnoh": "file:../rnoh",
+ "rnoh-push-notification": "file:../../node_modules/@react-native-oh-tpl/push-notification-ios/harmony/push_notification.har"
+ }
+```
+
+点击右上角的 `sync` 按钮
+
+或者在终端执行:
+
+```bash
+cd entry
+ohpm install
+```
+
+方法二:直接链接源码
+
+> [!TIP] 源码位于三方库安装路径的 `harmony` 文件夹下。
+
+打开 `entry/oh-package.json5`,添加以下依赖
+
+```json
+"dependencies": {
+ "rnoh": "file:../rnoh",
+ "rnoh-push-notification": "file:../../node_modules/@react-native-oh-tpl/push-notification-ios/harmony/push_notification"
+ }
+```
+
+打开终端,执行:
+
+```bash
+cd entry
+ohpm install --no-link
+```
+
+### 配置 CMakeLists 和引入 PushNotificationPackage
+
+打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
+
+```diff
+project(rnapp)
+cmake_minimum_required(VERSION 3.4.1)
+set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
+set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
+
+add_subdirectory("${RNOH_CPP_DIR}" ./rn)
+
+# RNOH_BEGIN: add_package_subdirectories
+add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
++ add_subdirectory("${OH_MODULE_DIR}/push_notification/src/main/cpp" ./push_notification)
+# RNOH_END: add_package_subdirectories
+
+add_library(rnoh_app SHARED
+ "./PackageProvider.cpp"
+ "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
+)
+
+target_link_libraries(rnoh_app PUBLIC rnoh)
+
+# RNOH_BEGIN: link_packages
+target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
++ target_link_libraries(rnoh_app PUBLIC rnoh_push_notification)
+# RNOH_END: link_packages
+```
+
+打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
+
+```diff
+#include "RNOH/PackageProvider.h"
+#include "SamplePackage.h"
++ #include "PushNotificationPackage.h"
+
+using namespace rnoh;
+
+std::vector> PackageProvider::getPackages(Package::Context ctx) {
+ return {
+ std::make_shared(ctx),
++ std::make_shared(ctx)
+ };
+}
+```
+### 在 ArkTs 侧引入 PushNotificationPackage
+
+打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
+
+```diff
+...
++ import { PushNotificationPackage } from 'rnoh-push-notification/ts';
+
+export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
+ return [
+ new SamplePackage(ctx),
++ new PushNotificationPackage(ctx)
+ ];
+}
+```
+### 运行
+
+点击右上角的 `sync` 按钮
+
+或者在终端执行:
+
+```bash
+cd entry
+ohpm install
+```
+
+然后编译、运行即可。
+
+## 约束与限制
+
+## 兼容性
+要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
+
+请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[<@react-native-oh-tpl/push-notification-ios> Releases](https://github.com/react-native-oh-library/react-native-push-notification-ios/releases))
+
+本文档内容基于以下版本验证通过:
+
+RNOH:0.72.13; SDK:HarmonyOS NEXT Developer Preview1; IDE:DevEco Studio 4.1.3.500; ROM:2.0.0.58;
+
+## API
+
+> [!tip] "Platform"列表示该属性在原三方库上支持的平台。
+
+> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
+
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| ------------------------------- | ------------------------ | -------- | -------- | -------- | ----------------- |
+| addNotificationRequest | Sends notificationRequest to notification center at specified firedate. Fires immediately if firedate is not set. | function | no | IOS/HarmonyOS | yes |
+| setApplicationIconBadgeNumber | Sets the badge number for the app icon on the home screen | function | no | All | yes |
+| getDeliveredNotifications | Provides you with a list of the app’s notifications that are still displayed in Notification Center | function | no | All | yes |
+| removeAllDeliveredNotifications | Remove all delivered notifications from Notification Center | function | no | All | yes |
+| removeDeliveredNotifications | Removes the specified delivered notifications from Notification Center | function | no | All | yes |
+
+
+## 属性
+
+> [!tip] "Platform"列表示该属性在原三方库上支持的平台。
+
+> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
+
+以下属性已验证,更多属性详情请查看 [react-native-push-notification-ios的文档介绍](https://github.com/react-native-oh-library/react-native-push-notification)
+
+
+**Parameters:**
+
+*NotificationRequest:*
+
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| ------------| -------------| -------- | -------- | -------- | ----------------- |
+| `id` | Identifier of the notification | string | yes | All | yes |
+| `title` | A short description of the reason for the notification | string | yes | All | yes |
+| `subtitle` | A secondary description of the reason for the notification | string | no | All | yes |
+| `body` | The message displayed in the notificatio | string | yes | All | yes |
+| `badge` | The number to display as the app's icon badge | number | no | All | yes |
+| `fireDate` | The date and time when the system should deliver the notification | object | no | All | yes |
+| `repeats` | Sets notification to repeat | boolean | no | All | yes |
+| `isSilent` | If true, the notification will appear without sound | boolean | no | All | yes |
+| `userInfo` | An object containing additional notification data | object | no | All | yes |
+
+---
+
+## 遗留问题
+- [ ] HarmonyOS的NotificationManager的规格和IOS不一致,其NotificationRequest所含参数,在HarmonyOS上部分没有适配对应参数,问题: [issue#1](https://github.com/react-native-oh-library/react-native-push-notification/issues/1)
+- [ ] 原库部分接口在HarmonyOS中没有对应接口处理相关逻辑,问题: [issue#2](https://github.com/react-native-oh-library/react-native-push-notification/issues/2)
+## 其他
+
+## 开源协议
+
+本项目基于 [The MIT License (MIT)](https://github.com/react-native-push-notification/ios/blob/master/LICENSE) ,请自由地享受和参与开源。
--
Gitee