pushwoosh-react-native-plugin 6.1.57 → 6.1.59

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/README.md CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  - [Integration Guide](https://docs.pushwoosh.com/platform-docs/pushwoosh-sdk/cross-platform-frameworks/react-native/integrating-react-native-plugin) — step-by-step setup
27
27
  - [API Reference](docs/README.md) — full API documentation
28
- - [Sample Project](https://github.com/Pushwoosh/pushwoosh-react-native-sample) — ready-to-run demo app
28
+ - [Sample Project](https://github.com/Pushwoosh/pushwoosh-react-native-plugin/tree/master/example/demoapp) — ready-to-run demo app
29
29
 
30
30
  ## Features
31
31
 
package/docs/README.md CHANGED
@@ -46,6 +46,8 @@ DeviceEventEmitter.addListener('pushOpened', (e: Event) => {
46
46
  <tr class="even"><td><a href="#getpushtoken">getPushToken(success)</a></td></tr>
47
47
  <tr class="even"><td><a href="#gethwid">getHwid(success)</a></td></tr>
48
48
  <tr class="even"><td><a href="#setuserid">setUserId(userId, success, fail)</a></td></tr>
49
+ <tr class="even"><td><a href="#setemails">setEmails(emails, success, fail)</a></td></tr>
50
+ <tr class="even"><td><a href="#setuseremails">setUserEmails(userId, emails, success, fail)</a></td></tr>
49
51
  <tr class="even"><td><a href="#postevent">postEvent(event, attributes)</a></td></tr>
50
52
  <tr class="even"><td><a href="#setapplicationiconbadgenumber">setApplicationIconBadgeNumber(badgeNumber)</a></td></tr>
51
53
  <tr class="even"><td><a href="#getapplicationiconbadgenumber">getApplicationIconBadgeNumber(callback)</a></td></tr>
@@ -292,6 +294,75 @@ This allows data and events to be matched across multiple user devices.
292
294
  </table>
293
295
 
294
296
 
297
+ ### setEmails
298
+
299
+ ```js
300
+ setEmails(emails, success, fail)
301
+ ```
302
+
303
+ Registers email address(es) for the current user. The addresses are associated with the user identifier currently set on the device; if `setUserId` was never called, the device HWID is used as the identifier. Use `setUserEmails` to set the user identifier and the addresses in a single call.
304
+
305
+ <table width=100% style='background-color:#0EA7ED;'>
306
+ <colgroup>
307
+ <col width="10%" />
308
+ <col width="20%" />
309
+ <col width="70%" />
310
+ </colgroup>
311
+ <tbody>
312
+ <tr>
313
+ <th align="left" colspan="3"><strong>Parameters</strong></th>
314
+ </tr>
315
+ <tr class="even"><td>array</td><td><b>emails</b></td><td>Array of email addresses associated with the current user.</td></tr>
316
+ <tr class="even"><td>function</td><td><b>success</b></td><td>(optional) method success callback.</td></tr>
317
+ <tr class="even"><td>function</td><td><b>fail</b></td><td>(optional) method failure callback.</td></tr>
318
+ </tbody>
319
+ </table>
320
+
321
+ Example:
322
+
323
+ ```js
324
+ Pushwoosh.setEmails(["user@example.com"],
325
+ function() { console.warn("setEmails success"); },
326
+ function(error) { console.warn("setEmails failed: " + error); }
327
+ );
328
+ ```
329
+
330
+
331
+ ### setUserEmails
332
+
333
+ ```js
334
+ setUserEmails(userId, emails, success, fail)
335
+ ```
336
+
337
+ Registers email address(es) for a specific user identifier. The method sets the user identifier and registers the addresses in a single call, so data and events can be matched across multiple channels (push, email) for the same user. A separate `setUserId` call is not required.
338
+
339
+ <table width=100% style='background-color:#0EA7ED;'>
340
+ <colgroup>
341
+ <col width="10%" />
342
+ <col width="20%" />
343
+ <col width="70%" />
344
+ </colgroup>
345
+ <tbody>
346
+ <tr>
347
+ <th align="left" colspan="3"><strong>Parameters</strong></th>
348
+ </tr>
349
+ <tr class="even"><td>string</td><td><b>userId</b></td><td>Identifier of currently logged in user</td></tr>
350
+ <tr class="even"><td>array</td><td><b>emails</b></td><td>Array of email addresses associated with the user.</td></tr>
351
+ <tr class="even"><td>function</td><td><b>success</b></td><td>(optional) method success callback.</td></tr>
352
+ <tr class="even"><td>function</td><td><b>fail</b></td><td>(optional) method failure callback.</td></tr>
353
+ </tbody>
354
+ </table>
355
+
356
+ Example:
357
+
358
+ ```js
359
+ Pushwoosh.setUserEmails("user-123", ["user@example.com"],
360
+ function() { console.warn("setUserEmails success"); },
361
+ function(error) { console.warn("setUserEmails failed: " + error); }
362
+ );
363
+ ```
364
+
365
+
295
366
  ### postEvent
296
367
 
297
368
  ```js
package/index.d.ts CHANGED
@@ -51,8 +51,8 @@ declare module 'pushwoosh-react-native-plugin' {
51
51
  enableHuaweiPushNotifications(): void;
52
52
 
53
53
  //email methods
54
- setUserEmails(userId: string, emails: (string | string[]), success?: () => void, fail?: (error: Error) => void): void;
55
- setEmails(emails: (string | string[]), success?: () => void, fail?: (error: Error) => void): void;
54
+ setUserEmails(userId: string, emails: (string | string[]), success?: () => void, fail?: (error: string) => void): void;
55
+ setEmails(emails: (string | string[]), success?: () => void, fail?: (error: string) => void): void;
56
56
  //SMS and WhatsApp methods
57
57
  registerSMSNumber(phoneNumber: string): void;
58
58
  registerWhatsappNumber(phoneNumber: string): void;
package/index.js CHANGED
@@ -383,14 +383,26 @@ class PushNotification {
383
383
  // }
384
384
  // );
385
385
  //
386
- setUserEmails(userId: string, emails: Object, success: ?Function, fail: ?Function) {
386
+ setUserEmails(userId: string, emails: string | Array<string>, success: ?Function, fail: ?Function) {
387
387
  if (!success) {
388
388
  success = function() {};
389
389
  }
390
390
  if (!fail) {
391
391
  fail = function(error) {};
392
392
  }
393
- PushwooshModule.setUserEmails(userId, emails, success, fail);
393
+ // Both native SDKs return silently on an empty user id without touching the callback.
394
+ if (typeof userId !== 'string' || userId.length === 0) {
395
+ fail('userId must not be empty');
396
+ return;
397
+ }
398
+ // The native bridge accepts arrays only, while the public type allows a single address.
399
+ const emailsList = (Array.isArray(emails) ? emails : [emails])
400
+ .filter(email => typeof email === 'string' && email.length > 0);
401
+ if (emailsList.length === 0) {
402
+ fail('emails must be a non-empty array of strings');
403
+ return;
404
+ }
405
+ PushwooshModule.setUserEmails(userId, emailsList, success, fail);
394
406
  }
395
407
 
396
408
 
@@ -408,14 +420,21 @@ class PushNotification {
408
420
  // }
409
421
  // );
410
422
  //
411
- setEmails(emails: Object, success: ?Function, fail: ?Function) {
423
+ setEmails(emails: string | Array<string>, success: ?Function, fail: ?Function) {
412
424
  if (!success) {
413
425
  success = function() {};
414
426
  }
415
427
  if (!fail) {
416
428
  fail = function(error) {};
417
429
  }
418
- PushwooshModule.setEmails(emails, success, fail);
430
+ // The native bridge accepts arrays only, while the public type allows a single address.
431
+ const emailsList = (Array.isArray(emails) ? emails : [emails])
432
+ .filter(email => typeof email === 'string' && email.length > 0);
433
+ if (emailsList.length === 0) {
434
+ fail('emails must be a non-empty array of strings');
435
+ return;
436
+ }
437
+ PushwooshModule.setEmails(emailsList, success, fail);
419
438
  }
420
439
 
421
440
  //Function: registerSMSNumber
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pushwoosh-react-native-plugin",
3
- "version": "6.1.57",
3
+ "version": "6.1.59",
4
4
  "description": "This plugin allows you to send and receive push notifications. Powered by Pushwoosh (www.pushwoosh.com).",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |s|
2
2
  s.name = "pushwoosh-react-native-plugin"
3
- s.version = "6.1.57"
3
+ s.version = "6.1.59"
4
4
  s.summary = "React Native Pushwoosh Push Notifications module"
5
5
  s.requires_arc = true
6
6
  s.author = 'Pushwoosh'
@@ -8,13 +8,13 @@ Pod::Spec.new do |s|
8
8
  s.homepage = 'n/a'
9
9
  s.source = { :git => "https://github.com/Pushwoosh/pushwoosh-react-native-plugin.git" }
10
10
  s.source_files = 'src/ios/PushwooshPlugin/Pushwoosh.{h,m}', 'src/ios/PushwooshPlugin/PWEventDispatcher.{h,m}'
11
- s.platform = :ios, "11.0"
11
+ s.platform = :ios, "13.0"
12
12
  s.xcconfig = {
13
13
  "HEADER_SEARCH_PATHS" => "${PODS_ROOT}/Headers/Public/React"
14
14
  }
15
15
  s.static_framework = true
16
16
 
17
17
  s.dependency 'React'
18
- s.dependency 'PushwooshXCFramework', '7.0.33'
18
+ s.dependency 'PushwooshXCFramework', '7.2.3'
19
19
  s.dependency 'PushwooshInboxUIXCFramework'
20
20
  end
@@ -37,7 +37,7 @@ android {
37
37
  }
38
38
 
39
39
  ext {
40
- pushwoosh = "6.7.60"
40
+ pushwoosh = "6.10.2"
41
41
  }
42
42
 
43
43
  dependencies {
@@ -34,6 +34,40 @@ static id objectOrNull(id object) {
34
34
  }
35
35
  }
36
36
 
37
+ typedef void (^PWEmailsCompletion)(NSError *error);
38
+
39
+ // The SDK invokes the completion once per address, an RCTResponseSenderBlock only once:
40
+ // the first error wins, success is reported after the last address.
41
+ static PWEmailsCompletion emailsCompletionHandler(NSUInteger addressCount, RCTResponseSenderBlock successCallback, RCTResponseSenderBlock errorCallback) {
42
+ NSObject *lock = [NSObject new];
43
+ __block NSUInteger completedCount = 0;
44
+ __block BOOL responded = NO;
45
+
46
+ return ^(NSError *error) {
47
+ @synchronized (lock) {
48
+ if (responded) {
49
+ return;
50
+ }
51
+
52
+ if (error) {
53
+ responded = YES;
54
+ if (errorCallback) {
55
+ errorCallback(@[ objectOrNull([error localizedDescription]) ]);
56
+ }
57
+ return;
58
+ }
59
+
60
+ completedCount++;
61
+ if (completedCount >= addressCount) {
62
+ responded = YES;
63
+ if (successCallback) {
64
+ successCallback(@[]);
65
+ }
66
+ }
67
+ }
68
+ };
69
+ }
70
+
37
71
  static NSDictionary * gStartPushData = nil;
38
72
  static NSURL * gPushDeepLinkURL = nil; // Deep link URL for New Architecture support
39
73
  static NSString * const kRegistrationSuccesEvent = @"PWRegistrationSuccess";
@@ -253,35 +287,34 @@ RCT_EXPORT_METHOD(getPushToken:(RCTResponseSenderBlock)callback) {
253
287
  }
254
288
 
255
289
  RCT_EXPORT_METHOD(setEmails:(NSArray *)emails success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
256
- __block NSError* gError = nil;
257
- [[Pushwoosh sharedInstance] setEmails:emails completion:^(NSError * _Nullable error) {
258
- if (error) {
259
- gError = error;
290
+ if (emails.count == 0) {
291
+ // The SDK ignores an empty list without invoking the completion block.
292
+ if (errorCallback) {
293
+ errorCallback(@[ @"emails must be a non-empty array" ]);
260
294
  }
261
- }];
262
- if (!gError && successCallback) {
263
- successCallback(@[]);
264
- }
265
-
266
- if (gError && errorCallback) {
267
- errorCallback(@[ objectOrNull([gError localizedDescription]) ]);
295
+ return;
268
296
  }
297
+
298
+ [[Pushwoosh sharedInstance] setEmails:emails completion:emailsCompletionHandler(emails.count, successCallback, errorCallback)];
269
299
  }
270
300
 
271
301
  RCT_EXPORT_METHOD(setUserEmails:(NSString*)userId emails:(NSArray *)emails success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
272
- __block NSError* gError = nil;
273
- [[Pushwoosh sharedInstance] setUser:userId emails:emails completion:^(NSError * _Nullable error) {
274
- if (error) {
275
- gError = error;
302
+ if (userId.length == 0) {
303
+ // The SDK ignores an empty user id without invoking the completion block.
304
+ if (errorCallback) {
305
+ errorCallback(@[ @"userId must not be empty" ]);
276
306
  }
277
- }];
278
- if (!gError && successCallback) {
279
- successCallback(@[]);
307
+ return;
280
308
  }
281
-
282
- if (gError && errorCallback) {
283
- errorCallback(@[ objectOrNull([gError localizedDescription]) ]);
309
+
310
+ if (emails.count == 0) {
311
+ if (errorCallback) {
312
+ errorCallback(@[ @"emails must be a non-empty array" ]);
313
+ }
314
+ return;
284
315
  }
316
+
317
+ [[Pushwoosh sharedInstance] setUser:userId emails:emails completion:emailsCompletionHandler(emails.count, successCallback, errorCallback)];
285
318
  }
286
319
 
287
320
  RCT_EXPORT_METHOD(setTags:(NSDictionary*)tags success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {