forked from Pushwoosh/pushwoosh-react-native-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
324 lines (299 loc) · 8.32 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
'use strict';
import { NativeModules } from 'react-native';
const PushwooshModule = NativeModules.Pushwoosh;
//Class: PushNotification
//Use `PushNotification` to register device for push notifications on Pushwoosh and customize notification appearance.
//
//Example:
//(start code)
//DeviceEventEmitter.addListener('pushOpened', (e: Event) => {
// console.warn("pushOpened: " + JSON.stringify(e));
// alert(JSON.stringify(e));
//});
//
//const Pushwoosh = require('pushwoosh-react-native-plugin');
//
//Pushwoosh.init({ "pw_appid" : "XXXX-XXXX", "project_number" : "XXXXXXXXXXXXX" });
//
//Pushwoosh.register(
// (token) => {
// console.warn("Registered for pushes: " + token);
// },
// (error) => {
// console.warn("Failed to register: " + error);
// }
//);
//(end)
class PushNotification {
//Function: init
//Call this first thing with your Pushwoosh App ID (pw_appid parameter) and Google Project ID for Android (projectid parameter)
//
//Example:
//(start code)
// //initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
// Pushwoosh.init({ projectid: "XXXXXXXXXXXXXXX", pw_appid : "XXXXX-XXXXX" });
//(end)
init(config: Object, success: ?Function, fail: ?Function) {
if (!success) {
success = function() {};
}
if (!fail) {
fail = function(error) {};
}
PushwooshModule.init(config, success, fail);
}
//Function: register
//Call this to register for push notifications and retreive a push Token
//
//Example:
//(start code)
// Pushwoosh.registerDevice(
// function(token)
// {
// alert(token);
// },
// function(status)
// {
// alert("failed to register: " + status);
// }
// );
//(end)
register(success: ?Function, fail: ?Function) {
if (!success) {
success = function(token) {};
}
if (!fail) {
fail = function(error) {};
}
PushwooshModule.register(success, fail);
}
//Function: unregister
//Unregisters device from push notifications
unregister(success: ?Function, fail: ?Function) {
if (!success) {
success = function(token) {};
}
if (!fail) {
fail = function(error) {};
}
PushwooshModule.unregister(success, fail);
}
//Function: onPushOpen
//Deprecated - use DeviceEventEmitter.addListener('pushOpened', callback) instead
onPushOpen(callback: Function) {
PushwooshModule.onPushOpen(callback);
}
//Function: setTags
//Call this to set tags for the device
//
//Example:
//sets the following tags: "deviceName" with value "hello" and "deviceId" with value 10
//(start code)
// Pushwoosh.setTags({deviceName:"hello", deviceId:10},
// function(status) {
// console.warn('setTags success');
// },
// function(status) {
// console.warn('setTags failed');
// }
// );
//
// //setings list tags "MyTag" with values (array) "hello", "world"
// pushNotification.setTags({"MyTag":["hello", "world"]});
//(end)
setTags(tags: Object, success: ?Function, fail: ?Function) {
if (!success) {
success = function() {};
}
if (!fail) {
fail = function(error) {};
}
PushwooshModule.setTags(tags, success, fail);
}
//Function: getTags
//Call this to get tags for the device
//
//Example:
//(start code)
// Pushwoosh.getTags(
// function(tags)
// {
// console.warn('tags for the device: ' + JSON.stringify(tags));
// },
// function(error)
// {
// console.warn('get tags error: ' + JSON.stringify(error));
// }
// );
//(end)
getTags(success: Function, fail: ?Function) {
if (!fail) {
fail = function(error) {};
}
PushwooshModule.getTags(success, fail);
}
//Function: getPushToken
//Call this to get push token if it is available. Note the token also comes in registerDevice function callback.
//
//Example:
//(start code)
// Pushwoosh.getPushToken(
// function(token)
// {
// console.warn('push token: ' + token);
// }
// );
//(end)
getPushToken(success: Function) {
PushwooshModule.getPushToken(success);
}
//Function: getHwid
//Call this to get Pushwoosh HWID used for communications with Pushwoosh API
//
//Example:
//(start code)
// Pushwoosh.getHwid(
// function(token) {
// console.warn('Pushwoosh HWID: ' + token);
// }
// );
//(end)
getHwid(success: Function) {
PushwooshModule.getHwid(success);
}
//Function: setUserId
//[android, ios] Set User indentifier. This could be Facebook ID, username or email, or any other user ID.
//This allows data and events to be matched across multiple user devices.
//
//Parameters:
// "userId" - user string identifier
//
setUserId(userId: string) {
PushwooshModule.setUserId(userId);
}
//Function: postEvent
//[android, ios] Post events for In-App Messages. This can trigger In-App message display as specified in Pushwoosh Control Panel.
//
//Parameters:
// "event" - event to trigger
// "attributes" - object with additional event attributes
//
// Example:
//(start code)
// Pushwoosh.setUserId("XXXXXX");
// Pushwoosh.postEvent("buttonPressed", { "buttonNumber" : 4, "buttonLabel" : "banner" });
//(end)
postEvent(event: string, attributes: ?Object) {
if (!attributes) {
attributes = {};
}
PushwooshModule.postEvent(event, attributes);
}
//Function: startLocationTracking
//[android, ios, wp8, windows] Starts geolocation based push notifications. You need to configure Geozones in Pushwoosh Control panel.
//
//Parameters:
// "success" - success callback
// "fail" - error callback
//
startLocationTracking() {
PushwooshModule.startLocationTracking();
}
//Function: stopLocationTracking
//[android, ios, wp8, windows] Stops geolocation based push notifications
//
//Parameters:
// "success" - success callback
// "fail" - error callback
//
stopLocationTracking() {
PushwooshModule.stopLocationTracking();
}
//Function: setApplicationIconBadgeNumber
//[android, ios, wp8, windows] Set the application icon badge number
//
//Parameters:
// "badgeNumber" - icon badge number
//
setApplicationIconBadgeNumber(badgeNumber: number) {
PushwooshModule.setApplicationIconBadgeNumber(badgeNumber);
}
//Function: getApplicationIconBadgeNumber
//[android, ios] Returns the application icon badge number
//
//Parameters:
// "callback" - success callback
//
//Example:
//(start code)
// Pushwoosh.getApplicationIconBadgeNumber(function(badge){ alert(badge);} );
//(end)
getApplicationIconBadgeNumber(callback: Function) {
PushwooshModule.getApplicationIconBadgeNumber(callback);
}
//Function: addToApplicationIconBadgeNumber
//[android, ios] Adds value to the application icon badge
//
//Parameters:
// "badgeNumber" - incremental icon badge number
//
//Example:
//(start code)
// Pushwoosh.addToApplicationIconBadgeNumber(5);
// Pushwoosh.addToApplicationIconBadgeNumber(-5);
//(end)
addToApplicationIconBadgeNumber(badgeNumber: number) {
PushwooshModule.addToApplicationIconBadgeNumber(badgeNumber);
}
//Function: setMultiNotificationMode
//[android] Allows multiple notifications to be displayed in the Android Notification Center
setMultiNotificationMode(on: boolean) {
PushwooshModule.setMultiNotificationMode(on);
}
//Function: setLightScreenOnNotification
//[android] Turns the screen on if notification arrives
//
//Parameters:
// "on" - enable/disable screen unlock (is disabled by default)
//
setLightScreenOnNotification(on: boolean) {
PushwooshModule.setLightScreenOnNotification(on);
}
//Function: setEnableLED
//[android] Enables led blinking when notification arrives and display is off
//
//Parameters:
// "on" - enable/disable led blink (is disabled by default)
//
setEnableLED(on: boolean) {
PushwooshModule.setEnableLED(on);
}
//Function: setEnableLED
//[android] Set led color. Use with <setEnableLED>
//
//Parameters:
// "color" - led color in ARGB integer format
//
setColorLED(color: number) {
PushwooshModule.setColorLED(color);
}
//Function: setSoundType
//[android] Sets default sound to play when push notification arrive.
//
//Parameters:
// "type" - Sound type (0 - default, 1 - no sound, 2 - always)
//
setSoundType(type: number) {
PushwooshModule.setSoundType(type);
}
//Function: setVibrateType
//[android] Sets default vibration mode when push notification arrive.
//
//Parameters:
// "type" - Vibration type (0 - default, 1 - no vibration, 2 - always)
//
setVibrateType(type: number) {
PushwooshModule.setVibrateType(type);
}
}
module.exports = new PushNotification();