react-native-idosdk 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ 本文档记录 `react-native-idosdk` 的版本变更。从 `1.0.6` 开始维护。
4
+
5
+ ## [1.0.6] - 2026-07-13
6
+
7
+ ### 变更
8
+
9
+ - Android 原生模块包名调整为 `com.getui.reactnativeido`。
10
+ - Android 依赖由随包 JAR 迁移至个推 Maven 仓库,使用 `gsido 1.4.14.0` 与 `gtc 3.3.3.0`。
11
+ - 调整 Android Manifest 合并规则,保留应用侧配置的 `GETUI_APPID`、`GT_INSTALL_CHANNEL` 和 `GTSDK_VERSION`。
12
+ - AndroidDemo 改为直接引用当前插件工程,并补充 `GT_INSTALL_CHANNEL` 配置,便于联调 `1.0.6`。
13
+ - 更新 React Native、Android、iOS 和 HarmonyOS 集成文档,移除旧推送插件的配置和 API 说明。
14
+
15
+ ### 兼容性
16
+
17
+ - Android 最低 `minSdkVersion` 为 `23`。
18
+ - iOS 最低部署版本为 `12.0`。
package/README.md CHANGED
@@ -1,106 +1,92 @@
1
-
2
1
  # react-native-idosdk
3
- * idosdk 是个推官方开发的 IDOSDK React Native 插件,使用该插件可以方便快速地集成推送功能。
4
-
5
-
6
- # 环境
7
-
8
- 1. React Native Version
9
- "react": "18.3.1"
10
- "react-native": "0.75.4"
11
- 2. 当前react-native-idosdk版本 1.0.5
12
2
 
3
+ 个推 IDOSDK 的 React Native 插件,用于接入运营统计、事件采集和用户画像能力。
13
4
 
14
- # 1.安装
5
+ 当前版本:`1.0.6`。
15
6
 
16
- ### 1.1 使用 npm 自动安装
7
+ ## 安装
17
8
 
18
- 在您的项目根目录下执行
9
+ 在 React Native 项目根目录执行:
19
10
 
20
- ````js
21
- step1:添加npm包依赖
22
- npm install react-native-idosdk@latest --save
11
+ ```sh
12
+ npm install react-native-idosdk@1.0.6 --save
13
+ ```
23
14
 
15
+ React Native 0.60 及以上项目会自动链接原生模块。iOS 项目还需要安装 Pods:
24
16
 
25
- step2:iOS, pod项目, 链接iOS原生代码
17
+ ```sh
26
18
  npx pod-install
19
+ ```
27
20
 
21
+ Android 示例工程使用 React `19.0.0` 和 React Native `0.79.1`。请按项目所用 React Native 版本完成原生环境配置。
28
22
 
29
- step2: 链接 (非Autolinking项目, 和iOS非pod项目)
30
- react-native link
31
- ````
23
+ ## 配置
32
24
 
33
- ### 1.2 完整代码示例
34
-
35
- *[AndroidDemo](example/AndroidDemo)
36
- *[iOSDemo](example/iOSDemo)
25
+ 应用 AppID 请在[个推开发者中心](https://dev.getui.com)创建应用后获取。
37
26
 
38
- # 2. 配置
27
+ ### Android
39
28
 
40
- * appId 需要去 [个推官网](https://dev.getui.com) 注册后,在后台配置获取。
29
+ `android/app/src/main/AndroidManifest.xml` `<application>` 节点内配置 AppID 和安装渠道:
41
30
 
31
+ ```xml
32
+ <meta-data android:name="GETUI_APPID" android:value="你的 AppID" />
33
+ <meta-data android:name="GT_INSTALL_CHANNEL" android:value="" />
34
+ ```
42
35
 
43
- ## 2.1 Android
44
- * AndroidManifest.xml中添加配置
45
- ````xml
46
- <manifest>
47
- <application>
48
- <meta-data android:name="GETUI_APPID" android:value="你的appid"/>
49
- <meta-data android:name="GT_INSTALL_CHANNEL" android:value=""/>
50
- </application>
51
- </manifest>
52
- ````
53
- * 如果开启混淆
54
- ````proguard
55
- -keep class com.getui.gs.** { *; }
56
- -keep class com.getui.gtc.** {*;}
57
- ````
58
-
59
- ## 2.2 IOS
60
-
36
+ 插件已声明 IDOSDK 所需的原生依赖、权限和组件。无需添加 `react-native-getui`、`PUSH_APPKEY` 或 `PUSH_APPSECRET` 等旧推送插件配置。详细说明见[Android 集成文档](document/android.md)。
61
37
 
62
- ### 2.2.2 使用CocoaPods安装
38
+ ### iOS
63
39
 
64
- 如果是原生应用集成react-native
40
+ 使用 Autolinking 时只需执行 `npx pod-install`。旧项目如未启用 Autolinking,可在目标 target 的 `Podfile` 中加入:
65
41
 
66
- 如果你的 React Native 是通过 Cocoapods 来集成的则使用下面两个步骤来集成
67
-
68
- 1. 在Podfile中添加如下代码(需要写在对应的 target 里):
69
-
70
- ````
42
+ ```ruby
71
43
  pod 'IdoSdkRN', :path => '../node_modules/react-native-idosdk'
44
+ ```
72
45
 
73
- ````
74
-
75
- 2. 终端执行如下命令:
76
-
77
- ````
78
- pod install
46
+ 然后执行 `pod install`。IDOSDK 不需要在 `AppDelegate` 中注册推送、DeviceToken 或 VoIP;初始化请在 JavaScript 中调用 `startSdk`。详细说明见[iOS 集成文档](document/iOS.md)。
79
47
 
80
- ````
48
+ ### HarmonyOS
81
49
 
82
- **注意:**
50
+ HarmonyOS 当前需要手动 Link,完整流程见[鸿蒙文档](react-native-harmony-ido/README.md)。
83
51
 
84
- * 使用 pod 就不要使用 react-native link 了,不然会有冲突。
52
+ ## JavaScript 使用
85
53
 
86
- * iOS 工程中如果找不到头文件可能要在 TARGETS-> BUILD SETTINGS -> Search Paths -> Header Search Paths 添加如下如路径
54
+ 在调用其他接口前先配置可选项并初始化 SDK。`gtcid` 在初始化完成前可能为空,可在业务侧稍后再次读取。
87
55
 
88
- ```
89
- $(SRCROOT)/../node_modules/react-native-getui/ios/RCTGetuiModule
90
- ```
56
+ ```ts
57
+ import GetuiIdo from 'react-native-idosdk';
91
58
 
59
+ const appId = '你的 AppID';
60
+ const channel = 'rn';
92
61
 
93
- ### 2.4 API调用与订阅消息
62
+ GetuiIdo.setDebugEnable(__DEV__);
63
+ GetuiIdo.setSessionTime(30_000);
64
+ GetuiIdo.setMinAppActiveDuration(60_000);
65
+ GetuiIdo.setMaxAppActiveDuration(3_600_000);
94
66
 
95
- 查看示例
67
+ GetuiIdo.startSdk(appId, channel);
96
68
 
97
- android 与 ios 有部分API不同, 查看插件的index.js index.d.ts中API的注释
69
+ GetuiIdo.version((version) => {
70
+ console.log('IDOSDK version:', version);
71
+ });
98
72
 
73
+ GetuiIdo.gtcid((id) => {
74
+ console.log('gtcid:', id);
75
+ });
99
76
 
100
- ## 2.3 ohos
77
+ GetuiIdo.trackCountEvent('purchase', { sku: 'example', amount: 1 }, '');
78
+ GetuiIdo.setProfile({ memberLevel: 'gold' }, '');
79
+ ```
101
80
 
102
- [鸿蒙文档](react-native-harmony-ido/README.md)
81
+ 时间类配置的单位均为毫秒。支持的接口包括:
103
82
 
104
- ## 3.iOS注意事项
83
+ - 初始化与查询:`startSdk`、`gtcid`、`version`、`setDebugEnable`
84
+ - 会话与上传:`setSessionTime`、`setMinAppActiveDuration`、`setMaxAppActiveDuration`、`setEventUploadInterval`、`setEventForceUploadSize`、`setProfileUploadInterval`、`setProfileForceUploadSize`
85
+ - 用户与事件:`setUserId`、`registerEventProperties`、`trackCustomKeyValueEventBegin`、`trackCustomKeyValueEventEnd`、`trackCountEvent`、`setProfile`
86
+ - 平台差异:`setApplicationGroupIdentifier` 仅 iOS 生效;`setSyncGenerateGtcid` 和 `registerEventProperties` 暂未在 HarmonyOS 插件中提供。
105
87
 
88
+ ## 示例工程
106
89
 
90
+ - [AndroidDemo](example/AndroidDemo)
91
+ - [iOSDemo](example/iOSDemo)
92
+ - [OhosDemo](example/OhosDemo)
@@ -7,7 +7,7 @@ def safeExtGet(prop, fallback) {
7
7
  android {
8
8
  compileSdkVersion safeExtGet('compileSdkVersion', 34)
9
9
 
10
- namespace 'com.getui.reactnativegetui'
10
+ namespace 'com.getui.reactnativeido'
11
11
 
12
12
  defaultConfig {
13
13
  minSdkVersion safeExtGet('minSdkVersion', 23)
@@ -17,10 +17,15 @@ android {
17
17
  }
18
18
  }
19
19
 
20
- repositories {
21
- maven {
22
- url "https://mvn.getui.com/nexus/content/repositories/releases/"
20
+ rootProject.allprojects {
21
+ repositories {
22
+ maven {
23
+ url "https://mvn.getui.com/nexus/content/repositories/releases/"
24
+ }
23
25
  }
26
+ }
27
+
28
+ repositories {
24
29
  maven { url 'https://maven.aliyun.com/repository/google' }
25
30
  maven { url 'https://maven.aliyun.com/repository/public' }
26
31
  mavenLocal()
@@ -42,16 +47,8 @@ repositories {
42
47
  }
43
48
 
44
49
  dependencies {
45
- implementation fileTree(dir: "libs", include: ["*.jar"])
46
50
  implementation "com.facebook.react:react-native:+" // From node_modules
47
-
48
-
49
- // implementation 'com.getui.opt:hwp:3.1.2' // 华为
50
- // implementation 'com.getui.opt:xmp:3.3.3' // 小米
51
- // implementation 'com.assist-v3:oppo:3.5.0' // oppo
52
- // implementation 'com.assist-v3:vivo:3.2.0' // vivo
53
- // implementation 'com.getui.opt:mzp:3.2.4' // 魅族
54
- // implementation 'com.getui.opt:ups:3.0.3' // ups,ups目前支持坚果,索尼,海信手机
55
- // implementation 'com.getui.opt:honor:3.6.0' // 荣耀
51
+ implementation 'com.getui:gsido:1.4.14.0'
52
+ implementation 'com.getui:gtc:3.3.3.0'
56
53
 
57
54
  }
@@ -1,14 +1,22 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ xmlns:tools="http://schemas.android.com/tools"
2
3
  >
3
4
 
4
- <uses-sdk
5
- android:minSdkVersion="14"
6
- android:targetSdkVersion="30" />
7
5
  <uses-permission android:name="android.permission.INTERNET" />
8
6
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9
7
  <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
10
8
 
11
9
  <application>
10
+ <meta-data
11
+ android:name="GETUI_APPID"
12
+ tools:node="remove" />
13
+ <meta-data
14
+ android:name="GT_INSTALL_CHANNEL"
15
+ tools:node="remove" />
16
+ <meta-data
17
+ android:name="GTSDK_VERSION"
18
+ tools:node="remove" />
19
+
12
20
  <service
13
21
  android:name="com.getui.gtc.GtcService"
14
22
  android:exported="false" >
@@ -1,4 +1,4 @@
1
- package com.getui.reactnativegetui;
1
+ package com.getui.reactnativeido;
2
2
 
3
3
  import android.content.Context;
4
4
  import com.facebook.react.bridge.Arguments;
@@ -43,9 +43,13 @@ public class GetuiIdoModule extends ReactContextBaseJavaModule {
43
43
  @ReactMethod
44
44
  public void startSdk(String appid, String channel) {
45
45
  // 设置AppId
46
- if (!TextUtils.isEmpty(appid)){
46
+ if (!TextUtils.isEmpty(appid)) {
47
47
  GsConfig.setAppId(appid);
48
48
  }
49
+ // 设置安装渠道
50
+ if (!TextUtils.isEmpty(channel)) {
51
+ GsConfig.setInstallChannel(channel);
52
+ }
49
53
  // 预初始化
50
54
  GsManager.getInstance().preInit(mContext);
51
55
  // 初始化并注册gtcid
@@ -234,4 +238,4 @@ public class GetuiIdoModule extends ReactContextBaseJavaModule {
234
238
  .emit(eventName, params);
235
239
  }
236
240
 
237
- }
241
+ }
@@ -1,4 +1,4 @@
1
- package com.getui.reactnativegetui;
1
+ package com.getui.reactnativeido;
2
2
 
3
3
  import com.facebook.react.ReactPackage;
4
4
  import com.facebook.react.bridge.JavaScriptModule;
@@ -1,4 +1,4 @@
1
- package com.getui.reactnativegetui;
1
+ package com.getui.reactnativeido;
2
2
 
3
3
  import android.util.Log;
4
4
 
@@ -0,0 +1,323 @@
1
+ # Android 个推 Maven 依赖迁移实施计划
2
+
3
+ > **面向执行代理:** 必须使用 `superpowers:subagent-driven-development`(推荐)或 `superpowers:executing-plans`,逐项执行本计划。所有步骤使用复选框跟踪状态。
4
+
5
+ **目标:** 将 RN Android 插件的个推本地 JAR 替换为 `gsido:1.4.14.0` 和 `gtc:3.3.3.0` Maven 依赖,并保留通过 `startSdk(appid, channel)` 运行时配置 SDK 的能力。
6
+
7
+ **架构:** Maven AAR 负责提供用户运营 SDK、GTC 核心类和默认 Manifest 权限及组件;RN Bridge 继续负责在初始化前写入 App ID 与渠道。插件将个推仓库加入根项目的所有项目,并在 Manifest 合并时移除 AAR 的静态 App ID 与渠道元数据,使宿主应用无需为了运行时初始化而额外声明占位符。
8
+
9
+ **技术栈:** Gradle 8.13、Android Gradle Plugin、React Native 0.79.1、Java、个推 `gsido:1.4.14.0`、个推 `gtc:3.3.3.0`
10
+
11
+ ## 全局约束
12
+
13
+ - 只修改 Android RN 插件,不改 iOS 和 HarmonyOS 依赖。
14
+ - 必须删除 `android/libs/gs-1.4.12.0.jar` 和 `android/libs/gtc-3.2.18.0.jar`,避免重复类。
15
+ - 必须保留 `gsido` AAR 默认声明的全部权限和 `android:usesCleartextTraffic="true"`。
16
+ - JavaScript API 和 `startSdk(String appid, String channel)` 签名保持不变。
17
+ - 不覆盖或提交仓库中现有的包名迁移、示例应用及其他无关改动。
18
+ - `android/build.gradle` 和新的 `GetuiIdoModule.java` 已包含用户改动,实施阶段
19
+ 不自动提交生产文件,避免把不同工作混入同一提交。
20
+
21
+ ## 文件结构
22
+
23
+ - 修改 `android/build.gradle`:向根项目注入个推仓库、声明 Maven 依赖并移除本地 JAR `fileTree`。
24
+ - 删除 `android/libs/gs-1.4.12.0.jar`:移除旧用户运营 SDK。
25
+ - 删除 `android/libs/gtc-3.2.18.0.jar`:移除旧 GTC 核心 SDK。
26
+ - 修改 `android/src/main/AndroidManifest.xml`:移除 AAR 的静态 App ID 和渠道元数据。
27
+ - 修改 `android/src/main/java/com/getui/reactnativeido/GetuiIdoModule.java`:在 SDK 预初始化前应用非空渠道参数。
28
+ - 不新增业务源文件或测试框架。
29
+
30
+ ---
31
+
32
+ ### 任务 1:迁移 Gradle 依赖并配置宿主仓库
33
+
34
+ **文件:**
35
+
36
+ - 修改:`android/build.gradle:12-17`
37
+ - 修改:`android/build.gradle:44-47`
38
+ - 修改:`android/src/main/AndroidManifest.xml`
39
+ - 删除:`android/libs/gs-1.4.12.0.jar`
40
+ - 删除:`android/libs/gtc-3.2.18.0.jar`
41
+
42
+ **接口:**
43
+
44
+ - 输入:个推 Releases Maven 仓库 `https://mvn.getui.com/nexus/content/repositories/releases/`
45
+ - 输出:插件 `debugCompileClasspath` 和 `debugRuntimeClasspath` 中的 `com.getui:gsido:1.4.14.0`、`com.getui:gtc:3.3.3.0`
46
+
47
+ - [ ] **步骤 1:运行迁移前依赖断言,确认测试失败**
48
+
49
+ 运行:
50
+
51
+ ```bash
52
+ cd /Users/yangsihao/Downloads/AndroidStudioProjects/plugins/rn/ido/react-native-idosdk
53
+ test ! -f android/libs/gs-1.4.12.0.jar \
54
+ && test ! -f android/libs/gtc-3.2.18.0.jar \
55
+ && ! rg -n 'implementation fileTree' android/build.gradle \
56
+ && rg -n "implementation 'com.getui:gsido:1.4.14.0'" android/build.gradle \
57
+ && rg -n "implementation 'com.getui:gtc:3.3.3.0'" android/build.gradle
58
+ ```
59
+
60
+ 预期:命令返回非零状态,因为旧 JAR 和 `fileTree` 仍存在,两个 Maven 依赖尚未声明。
61
+
62
+ - [ ] **步骤 2:将个推仓库添加到根项目**
63
+
64
+ 在 `android/build.gradle` 中添加:
65
+
66
+ ```gradle
67
+ rootProject.allprojects {
68
+ repositories {
69
+ maven {
70
+ url "https://mvn.getui.com/nexus/content/repositories/releases/"
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ - [ ] **步骤 3:移除 AAR 的静态配置元数据**
77
+
78
+ 在插件 Manifest 中声明 `tools` 命名空间,并在 `<application>` 内添加:
79
+
80
+ ```xml
81
+ <meta-data
82
+ android:name="GETUI_APPID"
83
+ tools:node="remove" />
84
+ <meta-data
85
+ android:name="GT_INSTALL_CHANNEL"
86
+ tools:node="remove" />
87
+ ```
88
+
89
+ - [ ] **步骤 4:替换本地 JAR 依赖**
90
+
91
+ 将 `android/build.gradle` 的依赖块开头修改为:
92
+
93
+ ```gradle
94
+ dependencies {
95
+ implementation "com.facebook.react:react-native:+" // From node_modules
96
+ implementation 'com.getui:gsido:1.4.14.0'
97
+ implementation 'com.getui:gtc:3.3.3.0'
98
+ ```
99
+
100
+ 删除以下声明:
101
+
102
+ ```gradle
103
+ implementation fileTree(dir: "libs", include: ["*.jar"])
104
+ ```
105
+
106
+ - [ ] **步骤 5:删除旧 JAR 文件**
107
+
108
+ 运行:
109
+
110
+ ```bash
111
+ rm android/libs/gs-1.4.12.0.jar android/libs/gtc-3.2.18.0.jar
112
+ ```
113
+
114
+ 预期:`android/libs` 中不再存在 `.jar` 文件。
115
+
116
+ - [ ] **步骤 6:重新运行依赖断言,确认测试通过**
117
+
118
+ 运行:
119
+
120
+ ```bash
121
+ test ! -f android/libs/gs-1.4.12.0.jar \
122
+ && test ! -f android/libs/gtc-3.2.18.0.jar \
123
+ && ! rg -n 'implementation fileTree' android/build.gradle \
124
+ && rg -n "implementation 'com.getui:gsido:1.4.14.0'" android/build.gradle \
125
+ && rg -n "implementation 'com.getui:gtc:3.3.3.0'" android/build.gradle \
126
+ && rg -n 'rootProject\.allprojects' android/build.gradle \
127
+ && rg -n 'tools:node="remove"' android/src/main/AndroidManifest.xml
128
+ ```
129
+
130
+ 预期:命令返回零状态,并打印两个 Maven 坐标、根项目仓库声明和元数据移除规则。
131
+
132
+ - [ ] **步骤 7:验证插件依赖解析**
133
+
134
+ 运行:
135
+
136
+ ```bash
137
+ cd example/AndroidDemo/android
138
+ ./gradlew :react-native-idosdk:dependencies --configuration debugRuntimeClasspath
139
+ ```
140
+
141
+ 预期:`BUILD SUCCESSFUL`,依赖树包含:
142
+
143
+ ```text
144
+ com.getui:gsido:1.4.14.0
145
+ com.getui:gtc:3.3.3.0
146
+ ```
147
+
148
+ - [ ] **步骤 8:检查任务 1 的限定差异**
149
+
150
+ 运行:
151
+
152
+ ```bash
153
+ git diff --check -- android/build.gradle \
154
+ android/libs/gs-1.4.12.0.jar \
155
+ android/libs/gtc-3.2.18.0.jar
156
+ git diff -- android/build.gradle
157
+ git diff --stat -- android/libs/gs-1.4.12.0.jar \
158
+ android/libs/gtc-3.2.18.0.jar
159
+ ```
160
+
161
+ 预期:差异检查无空白错误;Gradle 差异包含已有 namespace 调整以及本任务的
162
+ 占位符和依赖修改;两个 JAR 显示为删除。本步骤不创建提交。
163
+
164
+ ### 任务 2:在运行时初始化中应用安装渠道
165
+
166
+ **文件:**
167
+
168
+ - 修改:`android/src/main/java/com/getui/reactnativeido/GetuiIdoModule.java:44-54`
169
+
170
+ **接口:**
171
+
172
+ - 输入:`startSdk(String appid, String channel)` 的 `channel` 参数
173
+ - 输出:在 `GsManager.preInit(Context)` 之前调用 `GsConfig.setInstallChannel(String)`
174
+
175
+ - [ ] **步骤 1:运行渠道配置断言,确认测试失败**
176
+
177
+ 运行:
178
+
179
+ ```bash
180
+ cd /Users/yangsihao/Downloads/AndroidStudioProjects/plugins/rn/ido/react-native-idosdk
181
+ rg -n 'GsConfig\.setInstallChannel\(channel\)' \
182
+ android/src/main/java/com/getui/reactnativeido/GetuiIdoModule.java
183
+ ```
184
+
185
+ 预期:命令返回非零状态,因为当前实现没有应用 `channel`。
186
+
187
+ - [ ] **步骤 2:实现非空渠道配置**
188
+
189
+ 将 `startSdk` 修改为:
190
+
191
+ ```java
192
+ @ReactMethod
193
+ public void startSdk(String appid, String channel) {
194
+ // 设置AppId
195
+ if (!TextUtils.isEmpty(appid)) {
196
+ GsConfig.setAppId(appid);
197
+ }
198
+ // 设置安装渠道
199
+ if (!TextUtils.isEmpty(channel)) {
200
+ GsConfig.setInstallChannel(channel);
201
+ }
202
+ // 预初始化
203
+ GsManager.getInstance().preInit(mContext);
204
+ // 初始化并注册gtcid
205
+ GsManager.getInstance().init(mContext);
206
+ Toast.makeText(mContext, "GsManager init ", Toast.LENGTH_SHORT).show();
207
+ }
208
+ ```
209
+
210
+ - [ ] **步骤 3:重新运行渠道配置断言,确认测试通过**
211
+
212
+ 运行:
213
+
214
+ ```bash
215
+ rg -n 'GsConfig\.setInstallChannel\(channel\)' \
216
+ android/src/main/java/com/getui/reactnativeido/GetuiIdoModule.java
217
+ ```
218
+
219
+ 预期:命令返回零状态,只匹配 `startSdk` 中的渠道设置调用。
220
+
221
+ - [ ] **步骤 4:编译 RN Android 插件**
222
+
223
+ 运行:
224
+
225
+ ```bash
226
+ cd example/AndroidDemo/android
227
+ ./gradlew :react-native-idosdk:compileDebugJavaWithJavac
228
+ ```
229
+
230
+ 预期:`BUILD SUCCESSFUL`,不存在 `GsManager`、`GsConfig` 或
231
+ `IGtcIdCallback` 的缺失类或缺失方法错误。
232
+
233
+ - [ ] **步骤 5:检查任务 2 的限定差异**
234
+
235
+ 运行:
236
+
237
+ ```bash
238
+ git diff --check -- \
239
+ android/src/main/java/com/getui/reactnativeido/GetuiIdoModule.java
240
+ git diff -- \
241
+ android/src/main/java/com/getui/reactnativeido/GetuiIdoModule.java
242
+ ```
243
+
244
+ 预期:未暂存差异只包含 `startSdk` 的渠道配置修改。本步骤不创建提交,也不改变
245
+ 该新文件原有的暂存状态。
246
+
247
+ ### 任务 3:验证 Manifest、依赖图和示例应用构建
248
+
249
+ **文件:**
250
+
251
+ - 验证:`example/AndroidDemo/android/app/build/intermediates/merged_manifests/debug/processDebugManifest/AndroidManifest.xml`
252
+ - 不修改生产文件;如果构建发现与本次迁移直接相关的问题,回到任务 1 或任务 2 修正并重新执行验证。
253
+
254
+ **接口:**
255
+
256
+ - 输入:任务 1 的 Maven 依赖与占位符、任务 2 的运行时配置
257
+ - 输出:可编译的 RN Android 插件和可构建的 Android Demo Debug APK
258
+
259
+ - [ ] **步骤 1:验证 Manifest 合并**
260
+
261
+ 运行:
262
+
263
+ ```bash
264
+ cd /Users/yangsihao/Downloads/AndroidStudioProjects/plugins/rn/ido/react-native-idosdk/example/AndroidDemo/android
265
+ ./gradlew :app:processDebugMainManifest
266
+ ```
267
+
268
+ 预期:`BUILD SUCCESSFUL`,宿主 App 能从个推仓库解析两个 AAR,且不存在
269
+ `GETUI_APPID` 或 `GT_INSTALL_CHANNEL` 的元数据值冲突。
270
+
271
+ - [ ] **步骤 2:检查合并后的 SDK 权限与组件**
272
+
273
+ 运行:
274
+
275
+ ```bash
276
+ MERGED_MANIFEST=$(find app/build/intermediates -path '*debug*' \
277
+ -name AndroidManifest.xml -print | head -n 1)
278
+ rg -n 'READ_PHONE_STATE|ACCESS_FINE_LOCATION|BLUETOOTH|GtcService|GtcProvider|usesCleartextTraffic' \
279
+ "$MERGED_MANIFEST"
280
+ ```
281
+
282
+ 预期:输出包含 `gsido` 默认敏感权限、`GtcService`、`GtcProvider` 和
283
+ `android:usesCleartextTraffic="true"`。
284
+
285
+ - [ ] **步骤 3:确认最终运行时依赖版本**
286
+
287
+ 运行:
288
+
289
+ ```bash
290
+ ./gradlew :app:dependencyInsight \
291
+ --configuration debugRuntimeClasspath \
292
+ --dependency com.getui:gsido
293
+ ./gradlew :app:dependencyInsight \
294
+ --configuration debugRuntimeClasspath \
295
+ --dependency com.getui:gtc
296
+ ```
297
+
298
+ 预期:两个命令均为 `BUILD SUCCESSFUL`,最终选择版本分别为
299
+ `1.4.14.0` 和 `3.3.3.0`,没有其他版本替换记录。
300
+
301
+ - [ ] **步骤 4:构建 Android Demo Debug APK**
302
+
303
+ 运行:
304
+
305
+ ```bash
306
+ ./gradlew :app:assembleDebug
307
+ ```
308
+
309
+ 预期:`BUILD SUCCESSFUL`,生成
310
+ `example/AndroidDemo/android/app/build/outputs/apk/debug/app-debug.apk`。
311
+
312
+ - [ ] **步骤 5:检查最终差异**
313
+
314
+ 运行:
315
+
316
+ ```bash
317
+ cd /Users/yangsihao/Downloads/AndroidStudioProjects/plugins/rn/ido/react-native-idosdk
318
+ git diff --check
319
+ git status --short
320
+ ```
321
+
322
+ 预期:`git diff --check` 无输出;`git status --short` 同时显示任务开始前已有的
323
+ 用户改动和本次 Maven 迁移改动。生产文件保持未提交,供用户与现有工作一起复核。
@@ -0,0 +1,96 @@
1
+ # Android 个推 Maven 依赖迁移设计
2
+
3
+ ## 目标
4
+
5
+ 将 Android React Native 插件内置的个推 JAR 文件替换为官方 Maven
6
+ 制品,同时保留插件通过运行时参数配置 App ID 和安装渠道的初始化方式。
7
+
8
+ ## 当前状态
9
+
10
+ - `android/libs/gs-1.4.12.0.jar` 提供用户运营 SDK API。
11
+ - `android/libs/gtc-3.2.18.0.jar` 提供个推核心 API 和 Android 组件。
12
+ - `android/build.gradle` 通过 `fileTree` 引入 `android/libs` 目录下的所有
13
+ JAR 文件。
14
+ - `startSdk(appid, channel)` 会在预初始化和初始化 `GsManager` 前设置
15
+ App ID,但目前没有使用传入的渠道参数。
16
+ - 插件 Manifest 显式声明了 GTC 服务和 Provider。
17
+
18
+ ## 选定方案
19
+
20
+ 使用精确的 Maven 版本,并移除内置 JAR 文件:
21
+
22
+ ```gradle
23
+ implementation 'com.getui:gsido:1.4.14.0'
24
+ implementation 'com.getui:gtc:3.3.3.0'
25
+ ```
26
+
27
+ 继续使用个推 Releases 仓库获取这两个制品。由于宿主 App 的运行时配置不会
28
+ 继承 RN Library 项目的仓库声明,插件需要将该仓库添加到根项目的所有项目:
29
+
30
+ ```gradle
31
+ rootProject.allprojects {
32
+ repositories {
33
+ maven {
34
+ url "https://mvn.getui.com/nexus/content/repositories/releases/"
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+ `android/libs` 当前只包含这两个 Android SDK JAR,因此移除范围较宽的
41
+ `fileTree` 依赖。这样可以避免完成 Maven 迁移后,旧版本 SDK JAR 被意外重新
42
+ 加入类路径。
43
+
44
+ ## 运行时配置
45
+
46
+ React Native API 保持不变。`startSdk(appid, channel)` 将按以下顺序执行:
47
+
48
+ 1. 当 App ID 非空时,通过 `GsConfig.setAppId(appid)` 设置 App ID。
49
+ 2. 当安装渠道非空时,通过 `GsConfig.setInstallChannel(channel)` 设置渠道。
50
+ 3. 按现有顺序调用 `GsManager.preInit(context)` 和
51
+ `GsManager.init(context)`。
52
+
53
+ 插件 Manifest 会通过 `tools:node="remove"` 移除 `gsido` AAR 声明的
54
+ `GETUI_APPID` 和 `GT_INSTALL_CHANNEL` 元数据。采用运行时配置的应用不需要
55
+ 为了完成 Manifest 合并而额外声明这两个占位符;宿主应用已经显式声明的同名
56
+ 元数据仍会保留。
57
+
58
+ ## Manifest 行为
59
+
60
+ `gsido:1.4.14.0` 和 `gtc:3.3.3.0` 的 AAR Manifest 将参与 Android
61
+ 标准 Manifest 合并。本次集成明确保留 SDK 默认声明的全部权限、Service、
62
+ Provider,以及 `android:usesCleartextTraffic="true"` 配置。仅移除用于静态
63
+ 配置的 App ID 和安装渠道元数据,因为 RN Bridge 会在初始化前动态设置这两个值。
64
+
65
+ 插件当前声明的 GTC Service 和 Provider 与 GTC AAR 中的组件名称及属性一致,
66
+ 可以继续保留,Manifest 合并器会将它们合并。除非实际合并时发生冲突,否则本次
67
+ 依赖迁移不额外删除这些声明。
68
+
69
+ ## 兼容性
70
+
71
+ `gsido:1.4.14.0` 继续提供 RN Bridge 当前使用的公开类和方法,包括
72
+ `GsManager`、`GsConfig` 和 `IGtcIdCallback`。Java 包导入和 JavaScript
73
+ API 签名均不需要调整。
74
+
75
+ 发布的 `gsido` 模块没有将 `gtc` 声明为传递依赖,因此必须同时显式声明这两个
76
+ Maven 依赖。
77
+
78
+ ## 验证方式
79
+
80
+ 验证范围包括:
81
+
82
+ - 检查 Gradle 文件是否声明两个精确的 Maven 坐标,并且不再引用本地 JAR。
83
+ - 验证能够从个推 Releases 仓库解析依赖。
84
+ - 验证宿主 App 能够解析个推 Maven 仓库,并正常完成 Android Manifest 合并。
85
+ - 验证 AAR 的两个静态配置元数据被移除,同时宿主 App 已声明的 App ID 保留。
86
+ - 使用新 AAR API 编译 React Native Android Library。
87
+ - 构建 Android 示例应用的 Debug 版本。
88
+ - 检查最终运行时依赖图,确认相关 SDK 类仅由 `gsido:1.4.14.0` 和
89
+ `gtc:3.3.3.0` 提供。
90
+
91
+ ## 不在本次范围内
92
+
93
+ - 修改 JavaScript API 签名。
94
+ - 移除个推 SDK 声明的权限。
95
+ - 修改 iOS 或 HarmonyOS 依赖。
96
+ - 重构无关的 Bridge 代码或现有包名调整。
@@ -1,112 +1,48 @@
1
- # Android 手动集成方式
2
-
3
-
4
- 在 react-native link 之后(非AutoLinking项目), 使用Android Studio打开工程(假设主模块名称为app),当然您也可以不适用Android Studio。
5
-
6
-
7
- 1、android/app/build.gradle 的defaultConfig节点中添加如下代码
8
-
9
- ````
10
- // 配置个推的三个参数
11
- manifestPlaceholders = [
12
- GETUI_APP_ID : "你的AppID",
13
- GETUI_APP_KEY : "你的AppKey",
14
- GETUI_APP_SECRET : "你的AppSecret"
15
- ]
16
-
17
- ````
18
-
19
- 2、在android/app/AndroidManifest.xml 的`<application>`标签内添加meta-data
20
-
21
- ````
22
- <!-- 配置个推的三个参数 -->
23
- <meta-data android:name="PUSH_APPID" android:value="${GETUI_APP_ID}" />
24
- <meta-data android:name="PUSH_APPKEY" android:value="${GETUI_APP_KEY}" />
25
- <meta-data android:name="PUSH_APPSECRET" android:value="${GETUI_APP_SECRET}" />
26
-
27
- ````
28
-
29
- 3、在android/app/build.gradle的`dependencies`节点中添加对react-native-getui的依赖(如果已经存在,忽略此步)
30
-
31
- ````
32
- compile project(':react-native-getui')
33
-
34
- ````
35
-
36
- #JS 使用
37
-
38
- 主要的消息通知回调使用如下,其他的接口均可在 [index.js](https://github.com/GetuiLaboratory/react-native-getui/blob/master/index.js) 查看。
39
-
40
- ````
41
- //订阅消息通知
42
- var { NativeAppEventEmitter } = require('react-native');
43
- var receiveRemoteNotificationSub = NativeAppEventEmitter.addListener(
44
- 'receiveRemoteNotification',
45
- (notification) => {
46
- //消息类型分为 cmd 和 payload 透传消息,具体的消息体格式会有差异
47
- switch (notification.type) {
48
- case "cid":
49
- Alert.alert('初始化获取到cid',JSON.stringify(notification))
50
- break;
51
- case "cmd":
52
- Alert.alert('cmd 消息通知',JSON.stringify(notification))
53
- break;
54
- case "payload":
55
- Alert.alert('payload 消息通知',JSON.stringify(notification))
56
- break;
57
- //新增回调通知到达,点击回调
58
- case 'notificationArrived':
59
- Alert.alert('notificationArrived 通知到达',JSON.stringify(notification))
60
- break
61
- case 'notificationClicked':
62
- Alert.alert('notificationArrived 通知点击',JSON.stringify(notification))
63
- break
64
- default:
65
- }
66
- }
67
- );
68
-
69
-
70
- ````
71
-
72
- ````
73
- componentWillUnMount() {
74
- //记得在此处移除监听
75
- receiveRemoteNotificationSub.remove()
76
- }
77
-
78
- ````
79
-
80
- 其他接口:
81
-
82
- ````
83
- import Getui from 'react-native-getui'
84
-
85
- Getui.initPush()
86
-
87
- Getui.clientId((param)=> {
88
- this.setState({'clientId': param})
89
- })
90
-
91
- Getui.version((param)=> {
92
- this.setState({'version': param})
93
- })
94
-
95
- Getui.status((param)=> {
96
- let status = ''
97
- switch (param){
98
- case '0':
99
- status = '正在启动'
100
- break;
101
- case '1':
102
- status = '启动'
103
- break;
104
- case '2':
105
- status = '停止'
106
- break;
107
- }
108
- this.setState({'status': status})
109
- })
110
- //Getui...
111
-
112
- ````
1
+ # Android 集成
2
+
3
+ `react-native-idosdk` 接入的是 IDOSDK 运营统计能力,不是 `react-native-getui` 推送插件。
4
+
5
+ ## 前置条件
6
+
7
+ - Android `minSdkVersion` 不低于 `23`。
8
+ - React Native 0.60 及以上项目使用 Autolinking;不需要在 `settings.gradle` 中手动引入 `react-native-getui`。
9
+ - 插件会从个推 Maven 仓库解析 `gsido` 和 `gtc` 依赖。网络受限时,请确认工程可访问 `https://mvn.getui.com/nexus/content/repositories/releases/`。
10
+
11
+ ## 配置 AppID
12
+
13
+ `android/app/src/main/AndroidManifest.xml` 的 `<application>` 节点中添加:
14
+
15
+ ```xml
16
+ <meta-data android:name="GETUI_APPID" android:value="你的 AppID" />
17
+ <meta-data android:name="GT_INSTALL_CHANNEL" android:value="" />
18
+ ```
19
+
20
+ `GETUI_APPID` 是必填项,`GT_INSTALL_CHANNEL` 可按发布渠道填写。不要添加 `PUSH_APPID`、`PUSH_APPKEY`、`PUSH_APPSECRET`,IDOSDK 不使用这些推送参数。
21
+
22
+ ## 混淆
23
+
24
+ 若应用启用了 R8/ProGuard,在应用的混淆规则文件中加入:
25
+
26
+ ```proguard
27
+ -keep class com.getui.gs.** { *; }
28
+ -keep class com.getui.gtc.** { *; }
29
+ ```
30
+
31
+ ## 初始化与使用
32
+
33
+ 在 JavaScript 中配置并初始化:
34
+
35
+ ```ts
36
+ import GetuiIdo from 'react-native-idosdk';
37
+
38
+ GetuiIdo.setDebugEnable(__DEV__);
39
+ GetuiIdo.startSdk('你的 AppID', 'rn');
40
+
41
+ GetuiIdo.gtcid((gtcid) => {
42
+ console.log('gtcid:', gtcid);
43
+ });
44
+
45
+ GetuiIdo.trackCountEvent('page_view', { page: 'home' }, '');
46
+ ```
47
+
48
+ `gtcid` 的生成是异步过程。首次读取为空时,在初始化完成后再次读取即可。
package/document/iOS.md CHANGED
@@ -1,299 +1,47 @@
1
- # iOS 手动集成方式
1
+ # iOS 集成
2
2
 
3
- react-native link 之后,打开 iOS 工程。
4
- Xcode 工程中需要注册个推 SDK 、注册 deviceToken 、监听消息回调,才能正常使用推送服务,只需要通过以下几步即可集成:
3
+ `react-native-idosdk` 使用 IDOSDK iOS 原生依赖,不需要接入个推推送 SDK、注册 DeviceToken 或配置 VoIP。
5
4
 
6
- 1、AppDelegate.h 中添加如下代码,导入头文件并实现两个 Delegate:
5
+ ## 安装
7
6
 
8
- ````
9
- // 导入头文件
10
- #import <RCTGetuiModule/RCTGetuiModule.h>
11
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
12
- #import <UserNotifications/UserNotifications.h>
13
- #endif
14
- // 以下三个参数需要到个推官网注册应用获得
15
- #define kGtAppId @"iMahVVxurw6BNr7XSn9EF2"
16
- #define kGtAppKey @"yIPfqwq6OMAPp6dkqgLpG5"
17
- #define kGtAppSecret @"G0aBqAD6t79JfzTB6Z5lo5"
7
+ React Native 0.60 及以上项目会通过 Autolinking 加载插件。安装 npm 包后执行:
18
8
 
19
- // 这里需要实现 UNUserNotificationCenterDelegate,GeTuiSdkDelegate 两个 Delegate
20
- @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate,GeTuiSdkDelegate>
9
+ ```sh
10
+ npx pod-install
11
+ ```
21
12
 
22
- @property (nonatomic, strong) UIWindow *window;
13
+ 未使用 Autolinking 的旧项目,可在 `ios/Podfile` 对应 target 中添加:
23
14
 
24
- @end
25
- ````
26
- 2、AppDelegate.m 的didFinishLaunchingWithOptions 方法里面添加如下代码:
15
+ ```ruby
16
+ pod 'IdoSdkRN', :path => '../node_modules/react-native-idosdk'
17
+ ```
27
18
 
28
- ````
29
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
30
- {
31
- // 接入个推
32
- [GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:self];
33
- // 注册远程通知
34
- [self registerRemoteNotification];
35
- }
19
+ 随后执行:
36
20
 
37
- /** 注册远程通知 */
38
- - (void)registerRemoteNotification {
39
- /*
40
- 警告:Xcode8的需要手动开启“TARGETS -> Capabilities -> Push Notifications”
41
- */
21
+ ```sh
22
+ cd ios
23
+ pod install
24
+ ```
42
25
 
43
- /*
44
- 警告:该方法需要开发者自定义,以下代码根据APP支持的iOS系统不同,代码可以对应修改。
45
- 以下为演示代码,注意根据实际需要修改,注意测试支持的iOS系统都能获取到DeviceToken
46
- */
47
- if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
48
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 // Xcode 8编译会调用
49
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
50
- center.delegate = self;
51
- [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) {
52
- if (!error) {
53
- NSLog(@"request authorization succeeded!");
54
- }
55
- }];
26
+ 插件的 iOS 最低部署版本为 `12.0`。CocoaPods 会处理原生头文件和 IDOSDK 依赖,无需手动添加 Header Search Paths。
56
27
 
57
- [[UIApplication sharedApplication] registerForRemoteNotifications];
58
- #else // Xcode 7编译会调用
59
- UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
60
- UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
61
- [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
62
- [[UIApplication sharedApplication] registerForRemoteNotifications];
63
- #endif
64
- } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
65
- UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
66
- UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
67
- [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
68
- [[UIApplication sharedApplication] registerForRemoteNotifications];
69
- } else {
70
- UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert |
71
- UIRemoteNotificationTypeSound |
72
- UIRemoteNotificationTypeBadge);
73
- [[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];
74
- }
75
- }
28
+ ## 初始化与使用
76
29
 
77
- ````
30
+ 在 JavaScript 中初始化,不需要修改 `AppDelegate`:
78
31
 
79
- 3、在AppDelegate.m 的didRegisterForRemoteNotificationsWithDeviceToken 方法中注册 DeviceToken,如下所示:
32
+ ```ts
33
+ import GetuiIdo from 'react-native-idosdk';
80
34
 
81
- ````
82
- - (void)application:(UIApplication *)application
83
- didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
84
- // [ GTSDK ]:(新版)向个推服务器注册deviceToken
85
- [GeTuiSdk registerDeviceTokenData:deviceToken];
86
-
87
- // [ 测试代码 ] 日志打印DeviceToken
88
- NSLog(@"[ TestDemo ] [ DeviceToken(NSData) ]: %@\n\n", deviceToken);
89
- }
90
- ````
35
+ GetuiIdo.setDebugEnable(__DEV__);
36
+ GetuiIdo.setApplicationGroupIdentifier('group.com.example.app'); // 可选:App Group 场景
37
+ GetuiIdo.startSdk('你的 AppID', 'rn');
91
38
 
92
- 4、为了在收到推送点击进入应用能够获取该条推送内容需要在 AppDelegate.m didReceiveRemoteNotification 方法里面添加 [[NSNotificationCenter defaultCenter] postNotificationName: object:] 方法,注意:这里需要在两个方法里面加一个是iOS7以前的一个是iOS7即以后的,如果AppDelegate.m 没有这个两个方法则直接复制这两个方法,如下所示:
39
+ GetuiIdo.version((version) => {
40
+ console.log('IDOSDK version:', version);
41
+ });
93
42
 
94
- ````
95
- #pragma mark - APP运行中接收到通知(推送)处理 - iOS 10以下版本收到推送
43
+ GetuiIdo.setUserId('user-123');
44
+ GetuiIdo.trackCountEvent('page_view', { page: 'home' }, '');
45
+ ```
96
46
 
97
- /** APP已经接收到“远程”通知(推送) - 透传推送消息 */
98
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
99
-
100
- // [ GTSdk ]:将收到的APNs信息传给个推统计
101
- [GeTuiSdk handleRemoteNotification:userInfo];
102
-
103
- // 控制台打印接收APNs信息
104
- NSLog(@"\n>>>[Receive RemoteNotification]:%@\n\n", userInfo);
105
-
106
- [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_RECEIVE_REMOTE_NOTIFICATION object:@{@"type":@"apns",@"userInfo":userInfo}];
107
-
108
- completionHandler(UIBackgroundFetchResultNewData);
109
- }
110
-
111
- #pragma mark - iOS 10中收到推送消息
112
-
113
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
114
- // iOS 10: App在前台获取到通知
115
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
116
-
117
- NSLog(@"willPresentNotification:%@", notification.request.content.userInfo);
118
- [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_RECEIVE_REMOTE_NOTIFICATION object:@{@"type":@"apns",@"userInfo":notification.request.content.userInfo}];
119
-
120
- // 根据APP需要,判断是否要提示用户Badge、Sound、Alert
121
- completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
122
- }
123
-
124
- // iOS 10: 点击通知进入App时触发
125
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
126
-
127
- NSLog(@"didReceiveNotification:%@", response.notification.request.content.userInfo);
128
-
129
- // [ GTSdk ]:将收到的APNs信息传给个推统计
130
- [GeTuiSdk handleRemoteNotification:response.notification.request.content.userInfo];
131
- [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_CLICK_NOTIFICATION object:response.notification.request.content.userInfo];
132
-
133
- completionHandler();
134
- }
135
- #endif
136
-
137
- ````
138
-
139
- 5、在 AppDelegate.m 实现 GetuiDelegate 的代理方法并接受推送消息:
140
-
141
- ````
142
- #pragma mark - GeTuiSdkDelegate
143
-
144
- /** SDK启动成功返回cid */
145
- - (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
146
- // [4-EXT-1]: 个推SDK已注册,返回clientId
147
- [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_REGISTE_CLIENTID object:clientId];
148
- NSLog(@"\n>>[GTSdk RegisterClient]:%@\n\n", clientId);
149
- }
150
-
151
- /** SDK遇到错误回调 */
152
- - (void)GeTuiSdkDidOccurError:(NSError *)error {
153
- // [EXT]:个推错误报告,集成步骤发生的任何错误都在这里通知,如果集成后,无法正常收到消息,查看这里的通知。
154
- NSLog(@"\n>>[GTSdk error]:%@\n\n", [error localizedDescription]);
155
- }
156
-
157
-
158
- /** SDK收到透传消息回调 */
159
- - (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId {
160
- // [ GTSdk ]:汇报个推自定义事件(反馈透传消息)
161
- [GeTuiSdk sendFeedbackMessage:90001 andTaskId:taskId andMsgId:msgId];
162
-
163
- // 数据转换
164
- NSString *payloadMsg = nil;
165
- if (payloadData) {
166
- payloadMsg = [[NSString alloc] initWithBytes:payloadData.bytes length:payloadData.length encoding:NSUTF8StringEncoding];
167
- }
168
-
169
- // 控制台打印日志
170
- NSString *msg = [NSString stringWithFormat:@"taskId=%@,messageId:%@,payloadMsg:%@%@", taskId, msgId, payloadMsg, offLine ? @"<离线消息>" : @""];
171
- NSLog(@"\n>>[GTSdk ReceivePayload]:%@\n\n", msg);
172
- NSDictionary *userInfo = @{@"taskId":taskId,@"msgId":msgId,@"payloadMsg":payloadMsg,@"offLine":offLine?@"YES":@"NO"};
173
- [[NSNotificationCenter defaultCenter]postNotificationName:GT_DID_RECEIVE_REMOTE_NOTIFICATION object:@{@"type":@"payload",@"userInfo":userInfo}];
174
- }
175
-
176
- /** SDK收到sendMessage消息回调 */
177
- - (void)GeTuiSdkDidSendMessage:(NSString *)messageId result:(int)result {
178
- // 发送上行消息结果反馈
179
- NSString *msg = [NSString stringWithFormat:@"sendmessage=%@,result=%d", messageId, result];
180
- NSLog(@"\n>>[GTSdk DidSendMessage]:%@\n\n", msg);
181
- }
182
-
183
- /** SDK运行状态通知 */
184
- - (void)GeTuiSDkDidNotifySdkState:(SdkStatus)aStatus {
185
- // 通知SDK运行状态
186
- NSLog(@"\n>>[GTSdk SdkState]:%u\n\n", aStatus);
187
- }
188
-
189
- /** SDK设置推送模式回调 */
190
- - (void)GeTuiSdkDidSetPushMode:(BOOL)isModeOff error:(NSError *)error {
191
- if (error) {
192
- NSLog(@"\n>>[GTSdk SetModeOff Error]:%@\n\n", [error localizedDescription]);
193
- return;
194
- }
195
-
196
- NSLog(@"\n>>[GTSdk SetModeOff]:%@\n\n", isModeOff ? @"开启" : @"关闭");
197
- }
198
-
199
- ````
200
-
201
- #JS 使用及接口
202
-
203
- 主要的消息通知回调使用如下,其他的接口均可在 [index.js](https://github.com/GetuiLaboratory/react-native-getui/blob/master/index.js) 查看。
204
-
205
- ````
206
- //订阅消息通知
207
- var { NativeAppEventEmitter } = require('react-native');
208
- var resigsteClientIdSub = NativeAppEventEmitter.addListener(
209
- 'registeClientId',
210
- (clientId) => {
211
- Alert.alert(clientId);
212
- }
213
- )
214
- var receiveRemoteNotificationSub = NativeAppEventEmitter.addListener(
215
- 'receiveRemoteNotification',
216
- (notification) => {
217
- //消息类型分为 APNs 和 payload 透传消息,具体的消息体格式会有差异
218
- switch (notification.type) {
219
- case "apns":
220
- Alert.alert('APNs 消息通知',JSON.stringify(notification))
221
- break;
222
- case "payload":
223
- Alert.alert('payload 消息通知',JSON.stringify(notification))
224
- break;
225
- default:
226
- }
227
- }
228
- );
229
-
230
- var clickRemoteNotificationSub = NativeAppEventEmitter.addListener(
231
- 'clickRemoteNotification',
232
- (notification) => {
233
- Alert.alert('点击通知',JSON.stringify(notification))
234
- }
235
- );
236
-
237
- <!-- VoIP 推送通知回调 -->
238
-
239
- var voipPushPayloadSub =
240
- NativeAppEventEmitter.addListener(
241
- 'voipPushPayload',
242
- (notification) => {
243
- Alert.alert('VoIP 通知: ',JSON.stringify(notification))
244
- }
245
- );
246
- ````
247
- **注意**
248
-
249
- 为保证正确收到 VoIP 推送回调,需要先调用注册 VoIP 接口 `Getui.voipRegistration()`,并且需要打开推送统治权限,并且开启 VoIP 后台运行权限。
250
-
251
- ![VoIP 权限配置](https://github.com/GetuiLaboratory/react-native-getui/blob/master/example/document/img/ios_1.jpeg?raw=true)
252
-
253
- ````
254
- componentWillUnMount() {
255
- //记得在此处移除监听
256
- receiveRemoteNotificationSub.remove()
257
- clickRemoteNotificationSub.remove()
258
- resigsteClientIdSub.remove()
259
- voipPushPayloadSub.remove()
260
- }
261
- ````
262
-
263
- 其他接口:
264
-
265
- ````
266
- import Getui from 'react-native-getui'
267
-
268
- // 注册 VoIP 通知,只有注册后才能收到 VoIP 通知。
269
- Getui.voipRegistration();
270
-
271
- Getui.clientId((param)=> {
272
- this.setState({'clientId': param})
273
- })
274
-
275
- Getui.version((param)=> {
276
- this.setState({'version': param})
277
- })
278
-
279
- Getui.status((param)=> {
280
- let status = ''
281
- switch (param){
282
- case '0':
283
- status = '正在启动'
284
- break;
285
- case '1':
286
- status = '启动'
287
- break;
288
- case '2':
289
- status = '停止'
290
- break;
291
- }
292
- this.setState({'status': status})
293
- })
294
- //Getui...
295
-
296
- ````
297
- **注意:**
298
-
299
- Apple 在 iOS 10 中新增了Notification Service Extension机制,可在消息送达时进行业务处理。为精确统计消息送达率,在集成个推SDK时,可以添加 Notification Service Extension,并在 Extensions 中添加 GTExtensionSDK 的统计接口,实现消息展示回执统计功能。具体可参考[个推集成文档](https://docs.getui.com/getui/mobile/ios/xcode/)。
47
+ `setApplicationGroupIdentifier` 外,其余通用接口与 [README](../README.md) 中的 JavaScript API 一致。时间类配置的单位均为毫秒。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-idosdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Getui ido sdk plugin for react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,9 +1,12 @@
1
- [Github 地址]()
1
+ [Github 地址](https://github.com/GetuiLaboratory/react-native-idosdk/tree/main/react-native-harmony-ido)
2
2
 
3
3
  ## 安装与使用
4
- * 下载鸿蒙插件工程[gt-ido-ohos-plugin-1.0.0.tgz](gt-ido-ohos-plugin-1.0.0.tgz)
5
- * gt-ido-ohos-plugin-1.0.0.tgz放到RN工程下
6
- * 安装 , 如:npm install file:gt-ido-ohos-plugin/gt-ido-ohos-plugin-1.0.0.tgz
4
+
5
+ 下载 [gt-ido-ohos-plugin-1.0.1.tgz](gt-ido-ohos-plugin-1.0.1.tgz) 并放到 React Native 工程根目录,然后执行:
6
+
7
+ ```sh
8
+ npm install file:./gt-ido-ohos-plugin-1.0.1.tgz
9
+ ```
7
10
 
8
11
 
9
12
  下面的代码展示了这个库的基本使用场景:
@@ -27,7 +30,7 @@ function App(): React.JSX.Element {
27
30
  setVersion(ver);
28
31
  });
29
32
 
30
- const appId = 'djYjSlFVMf6p5YOy2OQUs8';
33
+ const appId = '你的 AppID';
31
34
  const channel = 'rn';
32
35
  GetuiIdo.setDebugEnable(true)
33
36
 
@@ -72,7 +75,6 @@ function App(): React.JSX.Element {
72
75
 
73
76
  GetuiIdo.trackCountEvent("123",profiles,"ss");
74
77
  };
75
- );
76
78
  }
77
79
  //....省略
78
80
  export default App;
@@ -105,7 +107,7 @@ export default App;
105
107
  ```json
106
108
  "dependencies": {
107
109
  "@rnoh/react-native-openharmony": "0.72.90",
108
- "IdoOhosSdk": "file:../../node_modules/gt-ido-ohos-plugin/IdoOhosSdk/IdoOhosSdk.har"
110
+ "IdoOhosSdk": "file:../../node_modules/gt-ido-ohos-plugin/harmony/IdoOhosSdk.har"
109
111
  }
110
112
  ```
111
113
  点击右上角的 `sync` 按钮
@@ -156,7 +158,7 @@ PackageProvider::getPackages(Package::Context ctx) {
156
158
  }
157
159
  ```
158
160
 
159
- ### 4.在 ArkTs 侧引入 NetInfoPackage
161
+ ### 4.在 ArkTS 侧引入 IdoPackage
160
162
 
161
163
  打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
162
164
 
@@ -179,7 +181,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
179
181
  "metadata": [
180
182
  {
181
183
  "name": "GETUI_APPID",
182
- "value": "djYjSlFVMf6p5YOy2OQUs8"//你的APPID个推官网申请
184
+ "value": "你的 AppID"
183
185
  },
184
186
 
185
187
  ],
@@ -261,4 +263,4 @@ trackCountEvent(eventId: string, args:{[key: string]: string|number|boolean}, ex
261
263
  setProfile(profiles: {[key: string]: string|number|boolean}, ext: string): void;
262
264
 
263
265
  }
264
- ```
266
+ ```
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "gt-ido-ohos-plugin",
3
- "version": "1.0.0",
4
- "description": "Add numbers with TurboModules",
3
+ "version": "1.0.1",
4
+ "description": "ido for ohos",
5
5
  "main": "index.ts",
6
6
  "keywords": [],
7
- "author": "",
7
+ "author": "yangshgetui",
8
8
  "license": "ISC",
9
9
  "harmony": {
10
10
  "alias": "gt-ido-ohos-plugin",
Binary file
Binary file