pushwoosh-react-native-plugin 6.1.25 → 6.1.27

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.
@@ -58,6 +58,7 @@ body:
58
58
  label: Your Pushwoosh React Native Plugin version
59
59
  description: Your React Native Plugin version which was integrated to the app. You may find it on the [releases page](https://github.com/Pushwoosh/pushwoosh-react-native-plugin/releases)
60
60
  options:
61
+ - 6.1.26
61
62
  - 6.1.25
62
63
  - 6.1.23
63
64
  - 6.1.22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pushwoosh-react-native-plugin",
3
- "version": "6.1.25",
3
+ "version": "6.1.27",
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.25"
3
+ s.version = "6.1.27"
4
4
  s.summary = "React Native Pushwoosh Push Notifications module"
5
5
  s.requires_arc = true
6
6
  s.author = 'Pushwoosh'
@@ -37,7 +37,7 @@ android {
37
37
  }
38
38
 
39
39
  ext {
40
- pushwoosh = "6.7.0"
40
+ pushwoosh = "6.7.2"
41
41
  }
42
42
 
43
43
  dependencies {
@@ -18,7 +18,7 @@
18
18
 
19
19
  #endif
20
20
 
21
- #define PUSHWOOSH_VERSION @"6.5.5"
21
+ #define PUSHWOOSH_VERSION @"6.5.7"
22
22
 
23
23
 
24
24
  @class Pushwoosh, PWMessage, PWNotificationCenterDelegateProxy;
@@ -365,6 +365,13 @@ Unregisters from push notifications.
365
365
  */
366
366
  - (NSString * _Nonnull)getHWID;
367
367
 
368
+ /**
369
+ Gets UserId.
370
+
371
+ @return userId. If the userId hasn't been set previously, then the userId is assigned the HWID.
372
+ */
373
+ - (NSString * _Nonnull)getUserId;
374
+
368
375
  /**
369
376
  Returns dictionary with enabled remove notificaton types.
370
377
 
@@ -26,6 +26,6 @@
26
26
  #import "PWInbox.h"
27
27
  #endif
28
28
 
29
- @interface PushwooshPlugin: RCTEventEmitter<RCTBridgeModule,PushNotificationDelegate>
29
+ @interface PushwooshPlugin: RCTEventEmitter<RCTBridgeModule, PushNotificationDelegate, UIApplicationDelegate>
30
30
 
31
31
  @end
@@ -13,6 +13,7 @@
13
13
  #import <React/RCTConvert.h>
14
14
 
15
15
  #import <UserNotifications/UserNotifications.h>
16
+ #import <Pushwoosh/PushNotificationManager.h>
16
17
 
17
18
  static id objectOrNull(id object) {
18
19
  if (object) {
@@ -33,6 +34,15 @@ static NSString * const kPushReceivedJSEvent = @"pushReceived";
33
34
 
34
35
  @implementation PushwooshPlugin
35
36
 
37
+ API_AVAILABLE(ios(10))
38
+ __weak id<UNUserNotificationCenterDelegate> _originalNotificationCenterDelegate;
39
+ API_AVAILABLE(ios(10))
40
+ struct {
41
+ unsigned int willPresentNotification : 1;
42
+ unsigned int didReceiveNotificationResponse : 1;
43
+ unsigned int openSettingsForNotification : 1;
44
+ } _originalNotificationCenterDelegateResponds;
45
+
36
46
  #pragma mark - Pushwoosh RCTBridgeModule
37
47
 
38
48
  RCT_EXPORT_MODULE(Pushwoosh);
@@ -61,10 +71,32 @@ RCT_EXPORT_METHOD(init:(NSDictionary*)config success:(RCTResponseSenderBlock)suc
61
71
  [PushNotificationManager initializeWithAppCode:appCode appName:nil];
62
72
  [[PushNotificationManager pushManager] sendAppOpen];
63
73
  [PushNotificationManager pushManager].delegate = self;
74
+ [[UIApplication sharedApplication] setDelegate:self];
64
75
 
65
76
  // We set Pushwoosh UNUserNotificationCenter delegate unless CUSTOM is specified in the config
66
77
  if(![notificationHandling isEqualToString:@"CUSTOM"]) {
67
- [UNUserNotificationCenter currentNotificationCenter].delegate = [PushNotificationManager pushManager].notificationCenterDelegate;
78
+ if (@available(iOS 10, *)) {
79
+
80
+ UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
81
+
82
+ if (notificationCenter.delegate != nil) {
83
+ _originalNotificationCenterDelegate = notificationCenter.delegate;
84
+ _originalNotificationCenterDelegateResponds.openSettingsForNotification =
85
+ (unsigned int)[_originalNotificationCenterDelegate
86
+ respondsToSelector:@selector(userNotificationCenter:openSettingsForNotification:)];
87
+ _originalNotificationCenterDelegateResponds.willPresentNotification =
88
+ (unsigned int)[_originalNotificationCenterDelegate
89
+ respondsToSelector:@selector(userNotificationCenter:
90
+ willPresentNotification:withCompletionHandler:)];
91
+ _originalNotificationCenterDelegateResponds.didReceiveNotificationResponse =
92
+ (unsigned int)[_originalNotificationCenterDelegate
93
+ respondsToSelector:@selector(userNotificationCenter:
94
+ didReceiveNotificationResponse:withCompletionHandler:)];
95
+ }
96
+
97
+ __strong PushwooshPlugin<UNUserNotificationCenterDelegate> *strongSelf = (PushwooshPlugin<UNUserNotificationCenterDelegate> *)self;
98
+ notificationCenter.delegate = (id<UNUserNotificationCenterDelegate>)strongSelf;
99
+ }
68
100
  }
69
101
 
70
102
  if (success) {
@@ -300,6 +332,127 @@ RCT_EXPORT_METHOD(performAction:(NSString*)code) {
300
332
  [PWInbox performActionForMessageWithCode:code];
301
333
  }
302
334
 
335
+ #pragma mark - UIApplicationDelegate Methods
336
+ #pragma mark -
337
+
338
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
339
+ [[Pushwoosh sharedInstance] handlePushRegistration:deviceToken];
340
+ }
341
+
342
+ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
343
+ [[Pushwoosh sharedInstance] handlePushRegistrationFailure:error];
344
+ }
345
+
346
+ #pragma mark - UNUserNotificationCenter Delegate Methods
347
+ #pragma mark -
348
+
349
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
350
+ willPresentNotification:(UNNotification *)notification
351
+ withCompletionHandler:
352
+ (void (^)(UNNotificationPresentationOptions options))completionHandler
353
+ API_AVAILABLE(ios(10.0)) {
354
+
355
+ if ([self isRemoteNotification:notification] && [PWMessage isPushwooshMessage:notification.request.content.userInfo]) {
356
+ UNMutableNotificationContent *content = notification.request.content.mutableCopy;
357
+
358
+ NSMutableDictionary *userInfo = content.userInfo.mutableCopy;
359
+ userInfo[@"pw_push"] = @(YES);
360
+
361
+ content.userInfo = userInfo;
362
+
363
+ //newsstand push
364
+ if (![self isContentAvailablePush:userInfo]) {
365
+ [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushReceivedEvent withArgs:@[ objectOrNull(userInfo) ]];
366
+
367
+ [self sendJSEvent:kPushReceivedJSEvent withArgs:userInfo];
368
+ }
369
+
370
+ completionHandler(UNNotificationPresentationOptionNone);
371
+ } else if ([PushNotificationManager pushManager].showPushnotificationAlert || [notification.request.content.userInfo objectForKey:@"pw_push"] == nil) {
372
+ completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
373
+ } else {
374
+ completionHandler(UNNotificationPresentationOptionNone);
375
+ }
376
+
377
+ if (_originalNotificationCenterDelegate != nil &&
378
+ _originalNotificationCenterDelegateResponds.willPresentNotification) {
379
+ [_originalNotificationCenterDelegate userNotificationCenter:center
380
+ willPresentNotification:notification
381
+ withCompletionHandler:completionHandler];
382
+ }
383
+ }
384
+
385
+ - (BOOL)isContentAvailablePush:(NSDictionary *)userInfo {
386
+ NSDictionary *apsDict = userInfo[@"aps"];
387
+ return apsDict[@"content-available"] != nil;
388
+ }
389
+
390
+ - (NSDictionary *)pushPayloadFromContent:(UNNotificationContent *)content {
391
+ return [[content.userInfo objectForKey:@"pw_push"] isKindOfClass:[NSDictionary class]] ? [content.userInfo objectForKey:@"pw_push"] : content.userInfo;
392
+ }
393
+
394
+ - (BOOL)isRemoteNotification:(UNNotification *)notification {
395
+ return [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]];
396
+ }
397
+
398
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
399
+ didReceiveNotificationResponse:(UNNotificationResponse *)response
400
+ withCompletionHandler:(void (^)(void))completionHandler
401
+ API_AVAILABLE(ios(10.0)) {
402
+ dispatch_block_t handlePushAcceptanceBlock = ^{
403
+ if (![response.actionIdentifier isEqualToString:UNNotificationDismissActionIdentifier]) {
404
+ if (![response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier] && [[PushNotificationManager pushManager].delegate respondsToSelector:@selector(onActionIdentifierReceived:withNotification:)]) {
405
+ [[PushNotificationManager pushManager].delegate onActionIdentifierReceived:response.actionIdentifier withNotification:[self pushPayloadFromContent:response.notification.request.content]];
406
+ }
407
+
408
+ [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(response.notification.request.content.userInfo) ]];
409
+
410
+ [self sendJSEvent:kPushOpenJSEvent withArgs:response.notification.request.content.userInfo];
411
+ }
412
+ };
413
+
414
+ if ([self isRemoteNotification:response.notification] && [PWMessage isPushwooshMessage:response.notification.request.content.userInfo]) {
415
+ if (![self isContentAvailablePush:response.notification.request.content.userInfo]) {
416
+ [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(response.notification.request.content.userInfo) ]];
417
+
418
+ [self sendJSEvent:kPushOpenJSEvent withArgs:response.notification.request.content.userInfo];
419
+ }
420
+
421
+ handlePushAcceptanceBlock();
422
+ } else if ([response.notification.request.content.userInfo objectForKey:@"pw_push"]) {
423
+ handlePushAcceptanceBlock();
424
+ }
425
+
426
+ if (_originalNotificationCenterDelegate != nil &&
427
+ _originalNotificationCenterDelegateResponds.didReceiveNotificationResponse) {
428
+ [_originalNotificationCenterDelegate userNotificationCenter:center
429
+ didReceiveNotificationResponse:response
430
+ withCompletionHandler:completionHandler];
431
+ } else {
432
+ completionHandler();
433
+ }
434
+ }
435
+
436
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
437
+ openSettingsForNotification:(nullable UNNotification *)notification
438
+ API_AVAILABLE(ios(10.0)) {
439
+ if ([[PushNotificationManager pushManager].delegate respondsToSelector:@selector(pushManager:openSettingsForNotification:)]) {
440
+ #pragma clang diagnostic push
441
+ #pragma clang diagnostic ignored "-Wpartial-availability"
442
+ [[PushNotificationManager pushManager].delegate pushManager:[PushNotificationManager pushManager] openSettingsForNotification:notification];
443
+ #pragma clang diagnostic pop
444
+ }
445
+
446
+ if (_originalNotificationCenterDelegate != nil &&
447
+ _originalNotificationCenterDelegateResponds.openSettingsForNotification) {
448
+ #pragma clang diagnostic push
449
+ #pragma clang diagnostic ignored "-Wunguarded-availability-new"
450
+ [_originalNotificationCenterDelegate userNotificationCenter:center
451
+ openSettingsForNotification:notification];
452
+ #pragma clang diagnostic pop
453
+ }
454
+ }
455
+
303
456
  - (NSDictionary*)inboxMessageToDictionary:(NSObject<PWInboxMessageProtocol>*) message {
304
457
  NSMutableDictionary* dictionary = [[NSMutableDictionary alloc] init];
305
458
  [dictionary setValue:@(message.type) forKey:@"type"];
@@ -581,18 +734,6 @@ RCT_EXPORT_METHOD(enableHuaweiPushNotifications) {
581
734
  [[PWEventDispatcher sharedDispatcher] dispatchEvent:kRegistrationErrorEvent withArgs:@[ objectOrNull([error localizedDescription]) ]];
582
735
  }
583
736
 
584
- - (void)onPushReceived:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
585
- [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushReceivedEvent withArgs:@[ objectOrNull(pushNotification) ]];
586
-
587
- [self sendJSEvent:kPushReceivedJSEvent withArgs:pushNotification];
588
- }
589
-
590
- - (void)onPushAccepted:(PushNotificationManager *)manager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
591
- [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(pushNotification) ]];
592
-
593
- [self sendJSEvent:kPushOpenJSEvent withArgs:pushNotification];
594
- }
595
-
596
737
  #pragma mark - RCTEventEmitter
597
738
 
598
739
  - (void)sendJSEvent:(NSString*)event withArgs:(NSDictionary*)args {
Binary file