pushwoosh-cordova-plugin 8.3.35 → 8.3.37

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.
@@ -0,0 +1,399 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ // Wait for the deviceready event before using any of Cordova's device APIs.
21
+ // See https://cordova.apache.org/docs/en/latest/cordova/events/events.html#deviceready
22
+ document.addEventListener('deviceready', onDeviceReady, false);
23
+
24
+ function onDeviceReady() {
25
+ var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");
26
+
27
+ console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
28
+ document.getElementById('deviceready').classList.add('ready');
29
+
30
+ pushwooshInitialize(pushwoosh);
31
+
32
+ registerForPushNotificationAction(pushwoosh);
33
+
34
+ setTagsAction(pushwoosh);
35
+ setLanguageAction(pushwoosh);
36
+ setUserIdAction(pushwoosh);
37
+ sendPostEventAction(pushwoosh);
38
+
39
+ getTagsAction(pushwoosh);
40
+ getPushTokenAction(pushwoosh);
41
+ getPushwooshHWIDAction(pushwoosh);
42
+
43
+ sendLocalNotificationAction(pushwoosh);
44
+ clearNotificationCenterAction(pushwoosh);
45
+ }
46
+
47
+ function setTagsAction(pushwoosh) {
48
+ document.getElementById('setTags').addEventListener('click', function() {
49
+ var key = document.getElementById("textField1").value;
50
+ var value = document.getElementById("textField2").value;
51
+ /**
52
+ * Function: setTags
53
+ * [android, ios, wp8, windows] Set tags for the device
54
+ *
55
+ * Parameters:
56
+ * "config" - object with custom device tags
57
+ * "success" - success callback
58
+ * "fail" - error callback
59
+ *
60
+ * | |
61
+ * | |
62
+ * __| |__
63
+ * \ /
64
+ * \ /
65
+ * \ /
66
+ * \__/
67
+ */
68
+ pushwoosh.setTags({key: key, value: value},
69
+ function() {
70
+ console.warn('setTags success');
71
+ },
72
+ function(error) {
73
+ console.warn('setTags failed');
74
+ })
75
+ });
76
+ }
77
+
78
+ function setLanguageAction(pushwoosh) {
79
+ document.getElementById('setLangBtn').addEventListener('click', function() {
80
+ var language = document.getElementById('textField3').value;
81
+
82
+ /**
83
+ * [android, ios] Set custom application language (as opposed to the default system language).
84
+ * This allows sending localized push messages
85
+ *
86
+ * Parameters:
87
+ * "language" - string containing language code, i.e. "en", "fr"
88
+ * | |
89
+ * | |
90
+ * __| |__
91
+ * \ /
92
+ * \ /
93
+ * \ /
94
+ * \__/
95
+ */
96
+ pushwoosh.setLanguage(language);
97
+ });
98
+ }
99
+
100
+ function setUserIdAction(pushwoosh) {
101
+ document.getElementById('setUserBtn').addEventListener('click', function() {
102
+ var userId = document.getElementById('textField4').value;
103
+
104
+ /**
105
+ * Function: setUserId
106
+ * [android, ios] Set User indentifier. This could be Facebook ID, username or email, or any other user ID.
107
+ * This allows data and events to be matched across multiple user devices.
108
+ *
109
+ * Parameters:
110
+ * "userId" - user string identifier
111
+ *
112
+ * | |
113
+ * | |
114
+ * __| |__
115
+ * \ /
116
+ * \ /
117
+ * \ /
118
+ * \__/
119
+ */
120
+ pushwoosh.setUserId(userId);
121
+ });
122
+ }
123
+
124
+ function sendPostEventAction(pushwoosh) {
125
+ document.getElementById('setPostEventBtn').addEventListener('click', function() {
126
+ var eventName = document.getElementById("textField5").value;
127
+
128
+ /**
129
+ * Function: postEvent
130
+ * [android, ios] Post events for In-App Messages. This can trigger In-App message display as specified in Pushwoosh Control Panel.
131
+ *
132
+ * Parameters:
133
+ * "event" - event to trigger
134
+ * "attributes" - object with additional event attributes
135
+ *
136
+ * | |
137
+ * | |
138
+ * __| |__
139
+ * \ /
140
+ * \ /
141
+ * \ /
142
+ * \__/
143
+ */
144
+
145
+ pushwoosh.postEvent(eventName, { "buttonNumber" : 4, "buttonLabel" : "banner" });
146
+ });
147
+ }
148
+
149
+ function getTagsAction(pushwoosh) {
150
+ document.getElementById('getTags').addEventListener('click', function() {
151
+ /**
152
+ * Function: getTags
153
+ * [android, ios, wp8, windows] Returns tags for the device including default tags
154
+ *
155
+ * Parameters:
156
+ * "success" - success callback. Receives tags as parameter
157
+ * "fail" - error callback
158
+ * | |
159
+ * | |
160
+ * __| |__
161
+ * \ /
162
+ * \ /
163
+ * \ /
164
+ * \__/
165
+ */
166
+ pushwoosh.getTags(
167
+ function(tags) {
168
+ console.log('tags for device: ' + JSON.stringify(tags));
169
+ },
170
+ function(error) {
171
+ console.log('get tags error: ' + JSON.stringify(error));
172
+ }
173
+ );
174
+ }, false);
175
+ }
176
+
177
+ function getPushTokenAction(pushwoosh) {
178
+ document.getElementById('getPushToken').addEventListener('click', function() {
179
+
180
+ /**
181
+ * Function: getPushToken
182
+ * [android, ios, wp8, windows] Returns push token if it is available. Note the token also comes in registerDevice function callback.
183
+ *
184
+ * Parameters:
185
+ * "success" - getPushToken callback
186
+ *
187
+ * | |
188
+ * | |
189
+ * __| |__
190
+ * \ /
191
+ * \ /
192
+ * \ /
193
+ * \__/
194
+ */
195
+ pushwoosh.getPushToken(
196
+ function(token) {
197
+ console.log('push token: ', + token);
198
+ }
199
+ );
200
+ }, false);
201
+ }
202
+
203
+ function getPushwooshHWIDAction(pushwoosh) {
204
+ document.getElementById('getHwid').addEventListener('click', function() {
205
+
206
+ /**
207
+ * Function: getPushwooshHWID
208
+ * [android, ios, wp8, windows] Returns Pushwoosh HWID used for communications with Pushwoosh API
209
+ *
210
+ * Parameters:
211
+ * "success" - getPushwooshHWID callback
212
+ *
213
+ * | |
214
+ * | |
215
+ * __| |__
216
+ * \ /
217
+ * \ /
218
+ * \ /
219
+ * \__/
220
+ */
221
+ pushwoosh.getPushwooshHWID(
222
+ function(token) {
223
+ console.log('Pushwoosh HWID: ' + token);
224
+ }
225
+ );
226
+ });
227
+ }
228
+
229
+ function resetBadges(pushwoosh) {
230
+ document.getElementById('resetBadges').addEventListener('click', function() {
231
+
232
+ /**
233
+ * Function: setApplicationIconBadgeNumber
234
+ * [android, ios, wp8, windows] Set the application icon badge number
235
+ *
236
+ * Parameters:
237
+ * "badgeNumber" - icon badge number
238
+ *
239
+ * | |
240
+ * | |
241
+ * __| |__
242
+ * \ /
243
+ * \ /
244
+ * \ /
245
+ * \__/
246
+ */
247
+
248
+ pushwoosh.setApplicationIconBadgeNumber('0');
249
+ });
250
+ }
251
+
252
+ function sendLocalNotificationAction(pushwoosh) {
253
+ document.getElementById('localNotification').addEventListener('click', function() {
254
+
255
+ /**
256
+ * Function: createLocalNotification
257
+ * [android, ios] Schedules local notification.
258
+ *
259
+ * Parameters:
260
+ * "config.msg" - notification message
261
+ * "config.seconds" - notification delay in seconds
262
+ * "config.userData" - addition data to pass in notification
263
+ * "success" - success callback
264
+ * "fail" - error callback
265
+ *
266
+ * | |
267
+ * | |
268
+ * __| |__
269
+ * \ /
270
+ * \ /
271
+ * \ /
272
+ * \__/
273
+ */
274
+
275
+ pushwoosh.createLocalNotification({msg: 'Hello, Pushwoosh!', seconds: 5, userData: 'optional'});
276
+ });
277
+ }
278
+
279
+ function clearNotificationCenterAction(pushwoosh) {
280
+ document.getElementById('clearNotificationCenter').addEventListener('click', function() {
281
+
282
+ /**
283
+ * Function: cancelAllLocalNotifications
284
+ * [ios] Clears all notifications from the notification center
285
+ *
286
+ * | |
287
+ * | |
288
+ * __| |__
289
+ * \ /
290
+ * \ /
291
+ * \ /
292
+ * \__/
293
+ */
294
+
295
+ pushwoosh.cancelAllLocalNotifications();
296
+ });
297
+ }
298
+
299
+ function registerForPushNotificationAction(pushwoosh) {
300
+ var switcher = document.getElementById("switcher");
301
+
302
+ switcher.addEventListener("change", function () {
303
+ // Register for Push Notifications
304
+ if (this.checked) {
305
+
306
+ /**
307
+ * Function: registerDevice
308
+ * [android, ios, wp8, windows] Register device for push notifications and retreive a push Token
309
+ *
310
+ * Parameters:
311
+ * "success" - success callback. Push token is passed as "status.pushToken" parameter to this callback
312
+ * "fail" - error callback
313
+ *
314
+ * | |
315
+ * | |
316
+ * __| |__
317
+ * \ /
318
+ * \ /
319
+ * \ /
320
+ * \__/
321
+ */
322
+
323
+ pushwoosh.registerDevice(
324
+ function (status) {
325
+ var pushToken = status.pushToken;
326
+ // Handle successful registration here
327
+ console.log('Push token received: ', pushToken);
328
+ },
329
+ function (status) {
330
+ // Handle registration error here
331
+ console.error('Push registration failed: ', status);
332
+ }
333
+ );
334
+ } else {
335
+
336
+ /**
337
+ * Function: unregisterDevice
338
+ * [android, ios, wp8, windows] Unregister device form receiving push notifications
339
+ *
340
+ * Parameters:
341
+ * "success" - success callback
342
+ * "fail" - error callback
343
+ *
344
+ * | |
345
+ * | |
346
+ * __| |__
347
+ * \ /
348
+ * \ /
349
+ * \ /
350
+ * \__/
351
+ */
352
+
353
+ pushwoosh.unregisterDevice(
354
+ function (status) {
355
+ console.log('Success', status);
356
+ },
357
+ function (status) {
358
+ console.error('Fail', status);
359
+ }
360
+ );
361
+ }
362
+ });
363
+ }
364
+
365
+ function pushwooshInitialize(pushwoosh) {
366
+ // Should be called before pushwoosh.onDeviceReady
367
+ document.addEventListener('push-notification', function (event) {
368
+ var notification = event.notification;
369
+ // Handle push open here
370
+ console.log('Received push notification: ', notification);
371
+ });
372
+
373
+ /**
374
+ * Function: onDeviceReady
375
+ * [android, ios, wp8, windows] Initialize Pushwoosh plugin and trigger a start push message
376
+ * Should be called on every app launch
377
+ *
378
+ * Parameters:
379
+ * "config.appid" - Pushwoosh application code
380
+ * "config.projectid" - GCM project number for android platform
381
+ * "config.serviceName" - MPNS service name for wp8 platform
382
+ *
383
+ * initialize Pushwoosh with projectid:
384
+ * "GOOGLE_PROJECT_NUMBER", appid : "PUSHWOOSH_APP_ID", serviceName : "WINDOWS_PHONE_SERVICE".
385
+ * This will trigger all pending push notifications on start.
386
+ * | |
387
+ * | |
388
+ * __| |__
389
+ * \ /
390
+ * \ /
391
+ * \ /
392
+ * \__/
393
+ */
394
+ pushwoosh.onDeviceReady({
395
+ appid: "XXXXX-XXXXX",
396
+ projectid: "XXXXXXXXXXXXXXX",
397
+ serviceName: "XXXX"
398
+ });
399
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pushwoosh-cordova-plugin",
3
- "version": "8.3.35",
3
+ "version": "8.3.37",
4
4
  "description": "\n This plugin allows you to send and receive push notifications. Powered by Pushwoosh (www.pushwoosh.com).\n ",
5
5
  "main":"www/PushNotification.js",
6
6
  "typings":"types/index.d.ts",
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="pushwoosh-cordova-plugin" version="8.3.35">
2
+ <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="pushwoosh-cordova-plugin" version="8.3.37">
3
3
 
4
4
  <name>Pushwoosh</name>
5
5
 
@@ -77,13 +77,13 @@
77
77
  <framework src="com.github.bumptech.glide:glide:4.10.0" />
78
78
  <framework src="org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.60" />
79
79
 
80
- <framework src="com.pushwoosh:pushwoosh:6.7.16"/>
81
- <framework src="com.pushwoosh:pushwoosh-amazon:6.7.16"/>
82
- <framework src="com.pushwoosh:pushwoosh-firebase:6.7.16"/>
83
- <framework src="com.pushwoosh:pushwoosh-badge:6.7.16"/>
84
- <framework src="com.pushwoosh:pushwoosh-inbox:6.7.16"/>
85
- <framework src="com.pushwoosh:pushwoosh-inbox-ui:6.7.16"/>
86
- <framework src="com.pushwoosh:pushwoosh-huawei:6.7.16"/>
80
+ <framework src="com.pushwoosh:pushwoosh:6.7.24"/>
81
+ <framework src="com.pushwoosh:pushwoosh-amazon:6.7.24"/>
82
+ <framework src="com.pushwoosh:pushwoosh-firebase:6.7.24"/>
83
+ <framework src="com.pushwoosh:pushwoosh-badge:6.7.24"/>
84
+ <framework src="com.pushwoosh:pushwoosh-inbox:6.7.24"/>
85
+ <framework src="com.pushwoosh:pushwoosh-inbox-ui:6.7.24"/>
86
+ <framework src="com.pushwoosh:pushwoosh-huawei:6.7.24"/>
87
87
  </platform>
88
88
 
89
89
  <!-- ios -->
@@ -125,7 +125,7 @@
125
125
  <source url="https://github.com/CocoaPods/Specs.git"/>
126
126
  </config>
127
127
  <pods use-frameworks="true">
128
- <pod name="PushwooshXCFramework" spec="6.7.11" />
128
+ <pod name="PushwooshXCFramework" spec="6.8.5" />
129
129
  <pod name="PushwooshInboxUIXCFramework" spec="6.1.2" />
130
130
  </pods>
131
131
  </podspec>
@@ -1070,6 +1070,15 @@ public class PushNotifications extends CordovaPlugin {
1070
1070
  return true;
1071
1071
  }
1072
1072
 
1073
+ @CordovaMethod
1074
+ private boolean setApiToken(String token) {
1075
+ if (token != null) {
1076
+ Pushwoosh.getInstance().setApiToken(token);
1077
+ return true;
1078
+ }
1079
+ return false;
1080
+ }
1081
+
1073
1082
  private static JSONObject inboxMessageToJson(InboxMessage message) {
1074
1083
  JSONObject object = new JSONObject();
1075
1084
  try {