forked from GetuiLaboratory/react-native-getui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
265 lines (245 loc) · 6.58 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import {
NativeModules,
DeviceEventEmitter,
NativeEventEmitter,
Platform
} from 'react-native';
const GetuiModule = NativeModules.GetuiModule;
//监听消息通知
var _onPushNotificationReceived = function (resp) {
console.log("个推消息:" + JSON.stringify(resp));
};
var _onClickPushNotification = function (resp) {
console.log("点击推送:" + JSON.stringify(resp));
};
var _onRegisteClientId = function (resp) {
console.log("注册ClientId:" + JSON.stringify(resp));
};
const GetuiEmitter = new NativeEventEmitter(GetuiModule);
const receiveSubscription = GetuiEmitter.addListener(
'receiveRemoteNotification',
(notification) => {
typeof (_onPushNotificationReceived) === 'function' && _onPushNotificationReceived(notification);
}
);
const clickSubscription = GetuiEmitter.addListener(
'clickRemoteNotification',
(notification) => {
typeof (_onClickPushNotification) === 'function' && _onClickPushNotification(notification);
}
);
const clientSubscription = GetuiEmitter.addListener(
'registeClientId',
(notification) => {
typeof (_onRegisteClientId) === 'function' && _onRegisteClientId(notification);
}
);
export default class Getui {
/**
* 初始化推送服务
*/
static initPush(){
GetuiModule.initPush();
}
/**
* 收到推送
*/
static onReceived(callback) {
_onPushNotificationReceived = callback;
}
/**
* 点击推送
*/
static onClickMessage(callback) {
_onClickPushNotification = callback;
}
/**
* 注册ClientId成功回调
*/
static onRegisteClientId(callback) {
_onRegisteClientId = callback;
}
/**
* 销毁SDK,并且释放资源
*/
static destroy() {
GetuiModule.destroy();
}
/**
* 恢复SDK运行,IOS7 以后支持Background Fetch方式,后台定期更新数据,该接口需要在Fetch起来后被调用,保证SDK 数据获取。
*/
static resume() {
GetuiModule.resume();
}
/**
* 获取SDK的Cid
*
* @return Cid值
*/
static clientId(cb) {
GetuiModule.clientId((param)=>{
cb(param)
});
}
/**
* 获取SDK运行状态
*
* @return 运行状态
*/
static status(cb) {
GetuiModule.status((param)=>{
cb(param)
});
}
/**
* 获取SDK版本号
*
* @return 版本值
*/
static version(cb) {
GetuiModule.version((param)=>{
cb(param)
});
}
/**
* 是否允许SDK 后台运行(默认值:NO)
* 备注:可以未启动SDK就调用该方法
* 警告:该功能会和音乐播放冲突,使用时请注意
*
* @param isEnable 支持当APP进入后台后,个推是否运行,YES.允许
*/
static runBackgroundEnable(isEnable) {
GetuiModule.runBackgroundEnable(isEnable);
}
/**
* 地理围栏功能,设置地理围栏是否运行
* 备注:SDK可以未启动就调用该方法
*
* @param isEnable 设置地理围栏功能是否运行(默认值:NO)
* @param isVerify 设置是否SDK主动弹出用户定位请求(默认值:NO)
*/
static lbsLocationEnable(isEnable, isVerify) {
GetuiModule.lbsLocationEnable(isEnable, isVerify);
}
/**
* 设置渠道
* 备注:SDK可以未启动就调用该方法
*
* SDK-1.5.0+
*
* @param aChannelId 渠道值,可以为空值
*/
static setChannelId(aChannelId) {
GetuiModule.setChannelId(aChannelId);
}
/**
* 向个推服务器注册DeviceToken
* 备注:可以未启动SDK就调用该方法
*
* @param deviceToken 推送时使用的deviceToken
*
*/
static registerDeviceToken(deviceToken) {
GetuiModule.registerDeviceToken(deviceToken);
}
/**
* 绑定别名功能:后台可以根据别名进行推送
*
* @param alias 别名字符串
* @param aSn 绑定序列码, 不为nil
*/
static bindAlias(alias, aSn = '0') {
GetuiModule.bindAlias(alias, aSn);
}
/**
* 取消绑定别名功能
*
* @param alias 别名字符串
* @param aSn 绑定序列码, 不为nil
*/
static unbindAlias(alias, aSn = '0') {
GetuiModule.unbindAlias(alias, aSn);
}
/**
* 给用户打标签 , 后台可以根据标签进行推送
*
* @param tags 别名数组
*
* @return 提交结果,YES表示尝试提交成功,NO表示尝试提交失败
*/
static setTag(tags) {
GetuiModule.setTag(tags);
}
/**
* 设置关闭推送模式(默认值:NO)
*
* @param isValue 消息推送开发,YES.关闭消息推送 NO.开启消息推送
*
* SDK-1.2.1+
*
*/
static setPushModeForOff(isValue) {
GetuiModule.setPushModeForOff(isValue);
}
/**
* 同步角标值到个推服务器
* 该方法只是同步角标值到个推服务器,本地仍须调用setApplicationIconBadgeNumber函数
*
* SDK-1.4.0+
*
* @param value 角标数值
*/
static setBadge(value) {
GetuiModule.setBadge(value);
}
static resetBadge() {
GetuiModule.resetBadge();
}
/**
* SDK发送上行消息结果
*
* @param body 需要发送的消息数据
* @param error 如果发送成功返回messageid,发送失败返回nil
*
* @return 消息的msgId
*/
static sendMessage(body, error) {
GetuiModule.sendMessage(body, error);
}
/**
* 上行第三方自定义回执actionid
*
* @param actionId 用户自定义的actionid,int类型,取值90001-90999。
* @param taskId 下发任务的任务ID
* @param msgId 下发任务的消息ID
*
* @return BOOL,YES表示尝试提交成功,NO表示尝试提交失败。注:该结果不代表服务器收到该条数据
* 该方法需要在回调方法“GeTuiSdkDidReceivePayload:andTaskId:andMessageId:andOffLine:fromApplication:”使用
*/
static sendFeedbackMessage(actionId, taskId, msgId, cb) {
GetuiModule.sendFeedbackMessage(actionId, taskId, msgId, (param)=>{
cb(param)
});
}
/***************** deprecated ******************/
/*
* React-native 只能 callback 一次,因此移除该形式,改用订阅模式监听消息
* 收到消息通知的回调
*/
// static receiveRemoteNotification(cb){
// GetuiModule.receiveRemoteNotification((param)=>{
// console.log('收到通知', JSON.stringify(param));
// cb(param)
// })
// }
/**
* React-native 只能 callback 一次,因此移除该形式,改用订阅模式监听消息
* 点击通知的回调,iOS10 以后才有该方法
*/
// static clickRemoteNotification(cb){
// GetuiModule.clickRemoteNotification((param)=>{
// console.log('点击通知', JSON.stringify(param));
// cb(param)
// })
// }
}