react-native-nitro-ali-push 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +240 -2
- package/android/CMakeLists.txt +31 -0
- package/android/build.gradle +139 -0
- package/android/src/main/AndroidManifest.xml +30 -0
- package/android/src/main/java/com/margelo/nitro/alipush/AliPushMessageReceiver.kt +156 -0
- package/android/src/main/java/com/margelo/nitro/alipush/HybridAliPushPlugin.kt +303 -0
- package/android/src/main/java/com/margelo/nitro/alipush/ThirdPartMessageActivity.kt +26 -0
- package/ios/HybridAliPushPlugin.swift +519 -0
- package/lib/index.d.ts +195 -0
- package/lib/index.js +269 -0
- package/lib/specs/AliPushPlugin.nitro.d.ts +88 -0
- package/lib/specs/AliPushPlugin.nitro.js +2 -0
- package/lib/types.d.ts +111 -0
- package/lib/types.js +11 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroAliPush+autolinking.cmake +84 -0
- package/nitrogen/generated/android/NitroAliPush+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroAliPushOnLoad.cpp +58 -0
- package/nitrogen/generated/android/NitroAliPushOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JAliPushAppState.hpp +61 -0
- package/nitrogen/generated/android/c++/JAliPushMessage.hpp +98 -0
- package/nitrogen/generated/android/c++/JAliPushMessageType.hpp +58 -0
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_AliPushMessage.hpp +87 -0
- package/nitrogen/generated/android/c++/JHybridAliPushPluginSpec.cpp +338 -0
- package/nitrogen/generated/android/c++/JHybridAliPushPluginSpec.hpp +78 -0
- package/nitrogen/generated/android/c++/JVariant_Double_String.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_Double_String.hpp +68 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_AliPushMessage.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_AliPushMessage.hpp +80 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_String.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_String.hpp +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/AliPushAppState.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/AliPushMessage.kt +91 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/AliPushMessageType.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/Func_void.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/Func_void_AliPushMessage.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/HybridAliPushPluginSpec.kt +123 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/NitroAliPushOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/Variant_Double_String.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/Variant_NullType_AliPushMessage.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/alipush/Variant_NullType_String.kt +62 -0
- package/nitrogen/generated/ios/NitroAliPush+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroAliPush-Swift-Cxx-Bridge.cpp +89 -0
- package/nitrogen/generated/ios/NitroAliPush-Swift-Cxx-Bridge.hpp +531 -0
- package/nitrogen/generated/ios/NitroAliPush-Swift-Cxx-Umbrella.hpp +60 -0
- package/nitrogen/generated/ios/NitroAliPushAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroAliPushAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridAliPushPluginSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridAliPushPluginSpecSwift.hpp +217 -0
- package/nitrogen/generated/ios/swift/AliPushAppState.swift +44 -0
- package/nitrogen/generated/ios/swift/AliPushMessage.swift +191 -0
- package/nitrogen/generated/ios/swift/AliPushMessageType.swift +40 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_AliPushMessage.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__variant_nitro__NullType__AliPushMessage_.swift +58 -0
- package/nitrogen/generated/ios/swift/HybridAliPushPluginSpec.swift +70 -0
- package/nitrogen/generated/ios/swift/HybridAliPushPluginSpec_cxx.swift +476 -0
- package/nitrogen/generated/ios/swift/Variant_Double_String.swift +30 -0
- package/nitrogen/generated/ios/swift/Variant_NullType_AliPushMessage.swift +30 -0
- package/nitrogen/generated/ios/swift/Variant_NullType_String.swift +30 -0
- package/nitrogen/generated/shared/c++/AliPushAppState.hpp +80 -0
- package/nitrogen/generated/shared/c++/AliPushMessage.hpp +123 -0
- package/nitrogen/generated/shared/c++/AliPushMessageType.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridAliPushPluginSpec.cpp +36 -0
- package/nitrogen/generated/shared/c++/HybridAliPushPluginSpec.hpp +85 -0
- package/package.json +61 -4
- package/react-native-nitro-ali-push.podspec +41 -0
- package/src/index.ts +284 -0
- package/src/specs/AliPushPlugin.nitro.ts +104 -0
- package/src/types.ts +117 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALI_PUSH_EVENT = void 0;
|
|
4
|
+
exports.initPush = initPush;
|
|
5
|
+
exports.getDeviceId = getDeviceId;
|
|
6
|
+
exports.bindAccount = bindAccount;
|
|
7
|
+
exports.unbindAccount = unbindAccount;
|
|
8
|
+
exports.bindTag = bindTag;
|
|
9
|
+
exports.unbindTag = unbindTag;
|
|
10
|
+
exports.listTags = listTags;
|
|
11
|
+
exports.addAlias = addAlias;
|
|
12
|
+
exports.removeAlias = removeAlias;
|
|
13
|
+
exports.listAliases = listAliases;
|
|
14
|
+
exports.setApplicationIconBadgeNumber = setApplicationIconBadgeNumber;
|
|
15
|
+
exports.getApplicationIconBadgeNumber = getApplicationIconBadgeNumber;
|
|
16
|
+
exports.getInitialMessage = getInitialMessage;
|
|
17
|
+
exports.getAuthorizationStatus = getAuthorizationStatus;
|
|
18
|
+
exports.syncBadgeNum = syncBadgeNum;
|
|
19
|
+
exports.addEventListener = addEventListener;
|
|
20
|
+
exports.removeEventListener = removeEventListener;
|
|
21
|
+
/**
|
|
22
|
+
* react-native-nitro-ali-push —— 阿里云移动推送 React Native 封装(Nitro Modules)。
|
|
23
|
+
*
|
|
24
|
+
* 提供账号 / 标签 / 别名绑定、设备号获取、角标管理,以及统一的推送消息事件订阅。
|
|
25
|
+
* 原生实现基于 Nitro Modules(HybridObject),iOS 端为 Swift、Android 端为 Kotlin,
|
|
26
|
+
* 由 `nitrogen` 代码生成器生成桥接层。
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
const react_native_nitro_modules_1 = require("react-native-nitro-modules");
|
|
31
|
+
const types_1 = require("./types");
|
|
32
|
+
Object.defineProperty(exports, "ALI_PUSH_EVENT", { enumerable: true, get: function () { return types_1.ALI_PUSH_EVENT; } });
|
|
33
|
+
/**
|
|
34
|
+
* 原生模块实例(Nitro HybridObject)。
|
|
35
|
+
*
|
|
36
|
+
* 若宿主工程未正确集成 Nitro 或缺少原生实现,会在此处抛错。
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
const AliPushNative = react_native_nitro_modules_1.NitroModules.createHybridObject('AliPushPlugin');
|
|
41
|
+
/**
|
|
42
|
+
* 初始化阿里云推送。
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* **Android**:调用此方法并通过 `appKey` / `appSecret` 向阿里云推送服务注册应用,
|
|
46
|
+
* 必须在 `App` 挂载前调用。需要在 `AndroidManifest.xml` 中配置推送 `AppKey` /
|
|
47
|
+
* `AppSecret`(见 README)。
|
|
48
|
+
*
|
|
49
|
+
* **iOS**:推送初始化在原生 `AppDelegate` 中通过 `CloudPushSDK` 完成,此方法在
|
|
50
|
+
* iOS 上为无操作。
|
|
51
|
+
*
|
|
52
|
+
* @param appKey - 阿里云推送控制台分配的 AppKey。
|
|
53
|
+
* @param appSecret - 阿里云推送控制台分配的 AppSecret。
|
|
54
|
+
* @returns 初始化完成的 Promise。
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* await AliPush.initPush('your_app_key', 'your_app_secret');
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function initPush(appKey, appSecret) {
|
|
62
|
+
return AliPushNative.initPush(appKey, appSecret);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 获取设备唯一标识 `deviceId`。
|
|
66
|
+
*
|
|
67
|
+
* @returns 解析为设备 `deviceId` 字符串的 Promise。
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const deviceId = await AliPush.getDeviceId();
|
|
72
|
+
* console.log(deviceId);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
function getDeviceId() {
|
|
76
|
+
return AliPushNative.getDeviceId();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 绑定账号。
|
|
80
|
+
*
|
|
81
|
+
* @param account - 待绑定的账号(字符串,长度建议 ≤ 64)。
|
|
82
|
+
* @returns 操作完成的 Promise。
|
|
83
|
+
*/
|
|
84
|
+
function bindAccount(account) {
|
|
85
|
+
return AliPushNative.bindAccount(account);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 解绑账号(解绑当前已绑定账号)。
|
|
89
|
+
*
|
|
90
|
+
* @returns 操作完成的 Promise。
|
|
91
|
+
*/
|
|
92
|
+
function unbindAccount() {
|
|
93
|
+
return AliPushNative.unbindAccount();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 绑定标签。
|
|
97
|
+
*
|
|
98
|
+
* @param target - 目标类型:`1` 设备 / `2` 账号 / `3` 别名。
|
|
99
|
+
* @param tags - 标签数组(字符串)。
|
|
100
|
+
* @param alias - 别名(可空,仅 `target = 3` 时生效)。
|
|
101
|
+
* @returns 操作完成的 Promise。
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* await AliPush.bindTag(1, ['news', 'sports'], null);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
function bindTag(target, tags, alias) {
|
|
109
|
+
return AliPushNative.bindTag(target, tags, alias);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 解绑标签。参数语义同 {@link bindTag}。
|
|
113
|
+
*
|
|
114
|
+
* @param target - 目标类型:`1` 设备 / `2` 账号 / `3` 别名。
|
|
115
|
+
* @param tags - 待解绑的标签数组。
|
|
116
|
+
* @param alias - 别名(可空)。
|
|
117
|
+
* @returns 操作完成的 Promise。
|
|
118
|
+
*/
|
|
119
|
+
function unbindTag(target, tags, alias) {
|
|
120
|
+
return AliPushNative.unbindTag(target, tags, alias);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 列出当前已绑定的标签。
|
|
124
|
+
*
|
|
125
|
+
* @param target - 目标类型:`1` 设备 / `2` 账号 / `3` 别名。
|
|
126
|
+
* @returns 解析为服务端响应字符串(含标签列表)的 Promise。
|
|
127
|
+
*/
|
|
128
|
+
function listTags(target) {
|
|
129
|
+
return AliPushNative.listTags(target);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 添加别名。
|
|
133
|
+
*
|
|
134
|
+
* @param alias - 待添加的别名。
|
|
135
|
+
* @returns 操作完成的 Promise。
|
|
136
|
+
*/
|
|
137
|
+
function addAlias(alias) {
|
|
138
|
+
return AliPushNative.addAlias(alias);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 移除别名。
|
|
142
|
+
*
|
|
143
|
+
* @param alias - 待移除的别名。
|
|
144
|
+
* @returns 操作完成的 Promise。
|
|
145
|
+
*/
|
|
146
|
+
function removeAlias(alias) {
|
|
147
|
+
return AliPushNative.removeAlias(alias);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 列出当前已添加的别名。
|
|
151
|
+
*
|
|
152
|
+
* @returns 解析为服务端响应字符串(含别名列表)的 Promise。
|
|
153
|
+
*/
|
|
154
|
+
function listAliases() {
|
|
155
|
+
return AliPushNative.listAliases();
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 设置应用角标(桌面图标右上角数字)。
|
|
159
|
+
*
|
|
160
|
+
* @param badge - 角标数字,`0` 表示清除。
|
|
161
|
+
* @returns 操作完成的 Promise。
|
|
162
|
+
*/
|
|
163
|
+
function setApplicationIconBadgeNumber(badge) {
|
|
164
|
+
return AliPushNative.setApplicationIconBadgeNumber(badge);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 获取应用当前角标数字。
|
|
168
|
+
*
|
|
169
|
+
* @returns 解析为当前角标数字的 Promise。
|
|
170
|
+
*/
|
|
171
|
+
function getApplicationIconBadgeNumber() {
|
|
172
|
+
return AliPushNative.getApplicationIconBadgeNumber();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 获取 App 冷启动(被通知唤起)时缓存的首条推送消息。
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* 当 App 完全退出后被通知点击唤起,JS 尚未完成订阅的窗口期内到达的消息会被原生端
|
|
179
|
+
* 缓存,待 JS 就绪后通过此方法或 {@link ALI_PUSH_EVENT} 事件返回。
|
|
180
|
+
*
|
|
181
|
+
* @returns 缓存消息对象,无则 `null`。
|
|
182
|
+
*/
|
|
183
|
+
function getInitialMessage() {
|
|
184
|
+
return AliPushNative.getInitialMessage();
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 获取 iOS 通知授权状态。
|
|
188
|
+
*
|
|
189
|
+
* @remarks Android 平台固定返回 `true`(Android 不做通知权限前置拦截)。
|
|
190
|
+
*
|
|
191
|
+
* @returns 解析为是否已授权的布尔值 Promise。
|
|
192
|
+
*/
|
|
193
|
+
function getAuthorizationStatus() {
|
|
194
|
+
return AliPushNative.getAuthorizationStatus();
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* 将角标数字同步到阿里云服务端。
|
|
198
|
+
*
|
|
199
|
+
* @remarks 仅 iOS 有效,Android 为无操作。
|
|
200
|
+
*
|
|
201
|
+
* @param badge - 角标数字。
|
|
202
|
+
* @returns 操作完成的 Promise。
|
|
203
|
+
*/
|
|
204
|
+
function syncBadgeNum(badge) {
|
|
205
|
+
return AliPushNative.syncBadgeNum(badge);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 订阅推送消息事件。
|
|
209
|
+
*
|
|
210
|
+
* @param event - 事件名,本库仅支持 {@link ALI_PUSH_EVENT}(`'aliyunPushReceived'`)。
|
|
211
|
+
* @param listener - 回调,参数为 {@link AliPushMessage}。
|
|
212
|
+
* @returns 退订函数,调用即可取消该监听。
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const unsubscribe = AliPush.addEventListener('aliyunPushReceived', (msg) => {
|
|
217
|
+
* console.log('收到推送', msg.title, msg.body);
|
|
218
|
+
* });
|
|
219
|
+
* // 不再需要时
|
|
220
|
+
* unsubscribe();
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
function addEventListener(event, listener) {
|
|
224
|
+
if (event !== types_1.ALI_PUSH_EVENT) {
|
|
225
|
+
console.warn(`[react-native-nitro-ali-push] Unsupported event: ${event}`);
|
|
226
|
+
return () => { };
|
|
227
|
+
}
|
|
228
|
+
return AliPushNative.addListener(listener);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* 取消订阅推送消息事件。
|
|
232
|
+
*
|
|
233
|
+
* @param unsubscribe - {@link addEventListener} 返回的退订函数。
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* AliPush.removeEventListener(unsubscribe);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
function removeEventListener(unsubscribe) {
|
|
241
|
+
unsubscribe?.();
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 默认导出对象(同时支持具名与默认导入)。
|
|
245
|
+
*
|
|
246
|
+
* @public
|
|
247
|
+
*/
|
|
248
|
+
const AliPush = {
|
|
249
|
+
initPush,
|
|
250
|
+
getDeviceId,
|
|
251
|
+
bindAccount,
|
|
252
|
+
unbindAccount,
|
|
253
|
+
bindTag,
|
|
254
|
+
unbindTag,
|
|
255
|
+
listTags,
|
|
256
|
+
addAlias,
|
|
257
|
+
removeAlias,
|
|
258
|
+
listAliases,
|
|
259
|
+
setApplicationIconBadgeNumber,
|
|
260
|
+
getApplicationIconBadgeNumber,
|
|
261
|
+
getInitialMessage,
|
|
262
|
+
getAuthorizationStatus,
|
|
263
|
+
syncBadgeNum,
|
|
264
|
+
addEventListener,
|
|
265
|
+
removeEventListener,
|
|
266
|
+
/** 事件名常量,便于 `addEventListener(AliPush.ALI_PUSH_EVENT, ...)`。 */
|
|
267
|
+
ALI_PUSH_EVENT: types_1.ALI_PUSH_EVENT,
|
|
268
|
+
};
|
|
269
|
+
exports.default = AliPush;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 阿里云推送(react-native-nitro-ali-push)的 Nitro 原生接口规格。
|
|
3
|
+
*
|
|
4
|
+
* 本文件由 `nitrogen`(Nitro 代码生成器)读取,生成 C++ 桥接层以及 iOS Swift /
|
|
5
|
+
* Android Kotlin 的实现桩。每个方法签名即为 JS 调用名(驼峰),与
|
|
6
|
+
* {@link "../index"} 中的封装函数一一对应。
|
|
7
|
+
*
|
|
8
|
+
* 事件订阅采用 Nitro 的回调约定:`addListener` 接收一个 JS 回调,返回用于
|
|
9
|
+
* 退订的 `() => void` 闭包(Nitro 会自动跨语言封送函数类型)。
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
import { type HybridObject } from 'react-native-nitro-modules';
|
|
14
|
+
import type { AliPushMessage } from '../types';
|
|
15
|
+
/**
|
|
16
|
+
* 推送消息事件回调类型。
|
|
17
|
+
*
|
|
18
|
+
* 参数即 {@link AliPushMessage},由原生端通过 {@link AliPushPlugin.addListener}
|
|
19
|
+
* 注册的回调回传。
|
|
20
|
+
*/
|
|
21
|
+
export type AliPushListener = (message: AliPushMessage) => void;
|
|
22
|
+
/**
|
|
23
|
+
* 阿里云推送原生模块(HybridObject)规格。
|
|
24
|
+
*
|
|
25
|
+
* - iOS 实现语言:`swift`(`HybridAliPushPlugin`)
|
|
26
|
+
* - Android 实现语言:`kotlin`(`HybridAliPushPlugin`)
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export interface AliPushPlugin extends HybridObject<{
|
|
31
|
+
ios: 'swift';
|
|
32
|
+
android: 'kotlin';
|
|
33
|
+
}> {
|
|
34
|
+
/**
|
|
35
|
+
* 初始化阿里云推送。
|
|
36
|
+
*
|
|
37
|
+
* - **Android**:通过 `appKey` / `appSecret` 向阿里云推送服务注册应用。
|
|
38
|
+
* - **iOS**:初始化在原生 `AppDelegate` 中完成(见 README),此方法为无操作。
|
|
39
|
+
*/
|
|
40
|
+
initPush(appKey: string, appSecret: string): Promise<void>;
|
|
41
|
+
/** 获取设备唯一标识 `deviceId`。 */
|
|
42
|
+
getDeviceId(): Promise<string>;
|
|
43
|
+
/** 绑定账号。 */
|
|
44
|
+
bindAccount(account: string): Promise<void>;
|
|
45
|
+
/** 解绑账号。 */
|
|
46
|
+
unbindAccount(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* 绑定标签。
|
|
49
|
+
*
|
|
50
|
+
* @param target 目标类型(1 设备 / 2 账号 / 3 别名)。
|
|
51
|
+
* @param tags 标签数组。
|
|
52
|
+
* @param alias 别名(可空)。
|
|
53
|
+
*/
|
|
54
|
+
bindTag(target: number, tags: string[], alias: string | null): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* 解绑标签。
|
|
57
|
+
*
|
|
58
|
+
* @param target 目标类型(1 设备 / 2 账号 / 3 别名)。
|
|
59
|
+
* @param tags 标签数组。
|
|
60
|
+
* @param alias 别名(可空)。
|
|
61
|
+
*/
|
|
62
|
+
unbindTag(target: number, tags: string[], alias: string | null): Promise<void>;
|
|
63
|
+
/** 列出当前标签(返回服务端响应字符串)。 */
|
|
64
|
+
listTags(target: number): Promise<string>;
|
|
65
|
+
/** 添加别名。 */
|
|
66
|
+
addAlias(alias: string): Promise<void>;
|
|
67
|
+
/** 移除别名。 */
|
|
68
|
+
removeAlias(alias: string): Promise<void>;
|
|
69
|
+
/** 列出当前别名(返回服务端响应字符串)。 */
|
|
70
|
+
listAliases(): Promise<string>;
|
|
71
|
+
/** 设置应用角标数字。 */
|
|
72
|
+
setApplicationIconBadgeNumber(badge: number): Promise<void>;
|
|
73
|
+
/** 获取应用当前角标数字。 */
|
|
74
|
+
getApplicationIconBadgeNumber(): Promise<number>;
|
|
75
|
+
/** 获取 App 冷启动(被通知唤起)时缓存的首条推送消息,无则 `null`。 */
|
|
76
|
+
getInitialMessage(): Promise<AliPushMessage | null>;
|
|
77
|
+
/** 获取 iOS 通知授权状态(Android 固定返回 `true`)。 */
|
|
78
|
+
getAuthorizationStatus(): Promise<boolean>;
|
|
79
|
+
/** 同步角标到阿里云服务端(仅 iOS 有效,Android 为无操作)。 */
|
|
80
|
+
syncBadgeNum(badge: number): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* 订阅推送消息事件。
|
|
83
|
+
*
|
|
84
|
+
* @param listener 收到消息时的回调。
|
|
85
|
+
* @returns 退订函数,调用即可取消该监听。
|
|
86
|
+
*/
|
|
87
|
+
addListener(listener: AliPushListener): () => void;
|
|
88
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 阿里云推送(react-native-nitro-ali-push)相关的 TypeScript 类型定义。
|
|
3
|
+
*
|
|
4
|
+
* 这些类型既用于描述 JS 端 API 的入参/返回值,也用于描述原生端通过
|
|
5
|
+
* `aliyunPushReceived` 事件回传给 JS 的推送载荷结构。
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { type AnyMap } from 'react-native-nitro-modules';
|
|
10
|
+
/**
|
|
11
|
+
* 消息类型。
|
|
12
|
+
*
|
|
13
|
+
* - `'notification'` 通知栏消息;
|
|
14
|
+
* - `'message'` 透传 / 非通知栏消息。
|
|
15
|
+
*
|
|
16
|
+
* 抽成命名类型,供 Nitro 代码生成器(nitrogen)识别(内联联合类型不被支持)。
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export type AliPushMessageType = 'notification' | 'message';
|
|
21
|
+
/**
|
|
22
|
+
* 收到消息时 App 所处的状态。
|
|
23
|
+
*
|
|
24
|
+
* - `'active'` 前台运行中;
|
|
25
|
+
* - `'inactive'` 非活跃(如来电打断);
|
|
26
|
+
* - `'background'` 后台。
|
|
27
|
+
*
|
|
28
|
+
* 抽成命名类型,供 Nitro 代码生成器识别。
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export type AliPushAppState = 'active' | 'inactive' | 'background';
|
|
33
|
+
/**
|
|
34
|
+
* 推送载荷。
|
|
35
|
+
*
|
|
36
|
+
* 无论是「通知栏消息」(notification) 还是「透传/非通知栏消息」(message),
|
|
37
|
+
* 原生端通过 {@link ALI_PUSH_EVENT | `aliyunPushReceived`} 事件回传给 JS 的
|
|
38
|
+
* 数据结构都遵循此接口。
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export interface AliPushMessage {
|
|
43
|
+
/** 通知标题。 */
|
|
44
|
+
title?: string;
|
|
45
|
+
/** 通知副标题(iOS 在前台/点击场景下可能携带)。 */
|
|
46
|
+
subtitle?: string;
|
|
47
|
+
/** 通知正文 / 内容。 */
|
|
48
|
+
body?: string;
|
|
49
|
+
/** 角标数字。 */
|
|
50
|
+
badge?: number;
|
|
51
|
+
/**
|
|
52
|
+
* 自定义键值对。
|
|
53
|
+
*
|
|
54
|
+
* 即推送后台设置的 `extras` / 业务参数,键为字符串,值可为字符串、数字、
|
|
55
|
+
* 布尔或嵌套结构(经 Nitro 的 {@link AnyMap} 跨语言封送)。
|
|
56
|
+
*/
|
|
57
|
+
extras?: AnyMap;
|
|
58
|
+
/**
|
|
59
|
+
* 消息类型:
|
|
60
|
+
*
|
|
61
|
+
* - `'notification'` 通知栏消息;
|
|
62
|
+
* - `'message'` 透传 / 非通知栏消息。
|
|
63
|
+
*/
|
|
64
|
+
type?: AliPushMessageType;
|
|
65
|
+
/**
|
|
66
|
+
* 点击行为标识:
|
|
67
|
+
*
|
|
68
|
+
* - `'opened'` 用户点击打开;
|
|
69
|
+
* - `'removed'` 用户删除;
|
|
70
|
+
* - 其它字符串表示自定义 action 标识。
|
|
71
|
+
*/
|
|
72
|
+
actionIdentifier?: string;
|
|
73
|
+
/**
|
|
74
|
+
* 收到消息时 App 所处的状态:
|
|
75
|
+
*
|
|
76
|
+
* - `'active'` 前台运行中;
|
|
77
|
+
* - `'inactive'` 非活跃(如来电打断);
|
|
78
|
+
* - `'background'` 后台。
|
|
79
|
+
*/
|
|
80
|
+
appState?: AliPushAppState;
|
|
81
|
+
/** 通知到达 / 点击的时间。iOS 为 `Date` 序列化后的值(数字时间戳或字符串)。 */
|
|
82
|
+
date?: number | string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 本库支持监听的事件名。
|
|
86
|
+
*
|
|
87
|
+
* 目前仅支持 {@link ALI_PUSH_EVENT}。
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export type AliPushEvent = typeof ALI_PUSH_EVENT;
|
|
92
|
+
/**
|
|
93
|
+
* 推送消息事件名常量。
|
|
94
|
+
*
|
|
95
|
+
* 通过 {@link addEventListener} 订阅,回调参数为 {@link AliPushMessage}。
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
export declare const ALI_PUSH_EVENT: "aliyunPushReceived";
|
|
100
|
+
/**
|
|
101
|
+
* 绑定 / 解绑标签时的目标类型。
|
|
102
|
+
*
|
|
103
|
+
* 对应阿里云推送 SDK 的 `target` 参数:
|
|
104
|
+
*
|
|
105
|
+
* - `1` 针对设备;
|
|
106
|
+
* - `2` 针对账号;
|
|
107
|
+
* - `3` 针对别名。
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
export type AliPushTagTarget = 1 | 2 | 3;
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ALI_PUSH_EVENT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 推送消息事件名常量。
|
|
6
|
+
*
|
|
7
|
+
* 通过 {@link addEventListener} 订阅,回调参数为 {@link AliPushMessage}。
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
exports.ALI_PUSH_EVENT = 'aliyunPushReceived';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
** linguist-generated=false
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#
|
|
2
|
+
# NitroAliPush+autolinking.cmake
|
|
3
|
+
# This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
# https://github.com/mrousavy/nitro
|
|
5
|
+
# Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
#
|
|
7
|
+
|
|
8
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
9
|
+
# to the current CMake project.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your CMakeLists.txt:
|
|
12
|
+
# ```cmake
|
|
13
|
+
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroAliPush+autolinking.cmake)
|
|
14
|
+
# ```
|
|
15
|
+
|
|
16
|
+
# Define a flag to check if we are building properly
|
|
17
|
+
add_definitions(-DBUILDING_NITROALIPUSH_WITH_GENERATED_CMAKE_PROJECT)
|
|
18
|
+
|
|
19
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
20
|
+
add_definitions(-DRN_SERIALIZABLE_STATE)
|
|
21
|
+
|
|
22
|
+
# Add all headers that were generated by Nitrogen
|
|
23
|
+
include_directories(
|
|
24
|
+
"../nitrogen/generated/shared/c++"
|
|
25
|
+
"../nitrogen/generated/android/c++"
|
|
26
|
+
"../nitrogen/generated/android/"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
30
|
+
target_sources(
|
|
31
|
+
# CMake project name (Android C++ library name)
|
|
32
|
+
NitroAliPush PRIVATE
|
|
33
|
+
# Autolinking Setup
|
|
34
|
+
../nitrogen/generated/android/NitroAliPushOnLoad.cpp
|
|
35
|
+
# Shared Nitrogen C++ sources
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridAliPushPluginSpec.cpp
|
|
37
|
+
# Android-specific Nitrogen C++ sources
|
|
38
|
+
../nitrogen/generated/android/c++/JHybridAliPushPluginSpec.cpp
|
|
39
|
+
../nitrogen/generated/android/c++/JVariant_NullType_AliPushMessage.cpp
|
|
40
|
+
../nitrogen/generated/android/c++/JVariant_Double_String.cpp
|
|
41
|
+
../nitrogen/generated/android/c++/JVariant_NullType_String.cpp
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
45
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
46
|
+
target_compile_definitions(
|
|
47
|
+
NitroAliPush PRIVATE
|
|
48
|
+
-DFOLLY_NO_CONFIG=1
|
|
49
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
50
|
+
-DFOLLY_USE_LIBCPP=1
|
|
51
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
52
|
+
-DFOLLY_MOBILE=1
|
|
53
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
54
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
55
|
+
# Once we target android-23 above, we can comment
|
|
56
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
57
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Add all libraries required by the generated specs
|
|
61
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
62
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
63
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
64
|
+
|
|
65
|
+
# Link all libraries together
|
|
66
|
+
target_link_libraries(
|
|
67
|
+
NitroAliPush
|
|
68
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
69
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
70
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
74
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
75
|
+
target_link_libraries(
|
|
76
|
+
NitroAliPush
|
|
77
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
78
|
+
)
|
|
79
|
+
else()
|
|
80
|
+
target_link_libraries(
|
|
81
|
+
NitroAliPush
|
|
82
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
83
|
+
)
|
|
84
|
+
endif()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroAliPush+autolinking.gradle
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
9
|
+
/// to the current Gradle project.
|
|
10
|
+
///
|
|
11
|
+
/// To use it, add this to your build.gradle:
|
|
12
|
+
/// ```gradle
|
|
13
|
+
/// apply from: '../nitrogen/generated/android/NitroAliPush+autolinking.gradle'
|
|
14
|
+
/// ```
|
|
15
|
+
|
|
16
|
+
logger.warn("[NitroModules] 🔥 NitroAliPush is boosted by nitro!")
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
sourceSets {
|
|
20
|
+
main {
|
|
21
|
+
java.srcDirs += [
|
|
22
|
+
// Nitrogen files
|
|
23
|
+
"${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroAliPushOnLoad.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#ifndef BUILDING_NITROALIPUSH_WITH_GENERATED_CMAKE_PROJECT
|
|
9
|
+
#error NitroAliPushOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "NitroAliPushOnLoad.hpp"
|
|
13
|
+
|
|
14
|
+
#include <jni.h>
|
|
15
|
+
#include <fbjni/fbjni.h>
|
|
16
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
|
+
|
|
18
|
+
#include "JHybridAliPushPluginSpec.hpp"
|
|
19
|
+
#include "JFunc_void.hpp"
|
|
20
|
+
#include "JFunc_void_AliPushMessage.hpp"
|
|
21
|
+
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
22
|
+
|
|
23
|
+
namespace margelo::nitro::alipush {
|
|
24
|
+
|
|
25
|
+
int initialize(JavaVM* vm) {
|
|
26
|
+
return facebook::jni::initialize(vm, []() {
|
|
27
|
+
::margelo::nitro::alipush::registerAllNatives();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
struct JHybridAliPushPluginSpecImpl: public jni::JavaClass<JHybridAliPushPluginSpecImpl, JHybridAliPushPluginSpec::JavaPart> {
|
|
32
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/alipush/HybridAliPushPlugin;";
|
|
33
|
+
static std::shared_ptr<JHybridAliPushPluginSpec> create() {
|
|
34
|
+
static const auto constructorFn = javaClassStatic()->getConstructor<JHybridAliPushPluginSpecImpl::javaobject()>();
|
|
35
|
+
jni::local_ref<JHybridAliPushPluginSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
|
|
36
|
+
return javaPart->getJHybridAliPushPluginSpec();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
void registerAllNatives() {
|
|
41
|
+
using namespace margelo::nitro;
|
|
42
|
+
using namespace margelo::nitro::alipush;
|
|
43
|
+
|
|
44
|
+
// Register native JNI methods
|
|
45
|
+
margelo::nitro::alipush::JHybridAliPushPluginSpec::CxxPart::registerNatives();
|
|
46
|
+
margelo::nitro::alipush::JFunc_void_cxx::registerNatives();
|
|
47
|
+
margelo::nitro::alipush::JFunc_void_AliPushMessage_cxx::registerNatives();
|
|
48
|
+
|
|
49
|
+
// Register Nitro Hybrid Objects
|
|
50
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
51
|
+
"AliPushPlugin",
|
|
52
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
53
|
+
return JHybridAliPushPluginSpecImpl::create();
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} // namespace margelo::nitro::alipush
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroAliPushOnLoad.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
10
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro::alipush {
|
|
13
|
+
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Register the native (C++) part of NitroAliPush, and autolinks all Hybrid Objects.
|
|
19
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
|
20
|
+
* inside a `facebook::jni::initialize(vm, ...)` call.
|
|
21
|
+
* Example:
|
|
22
|
+
* ```cpp (cpp-adapter.cpp)
|
|
23
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all NitroAliPush HybridObjects
|
|
26
|
+
* margelo::nitro::alipush::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
void registerAllNatives();
|
|
33
|
+
|
|
34
|
+
} // namespace margelo::nitro::alipush
|