@trycourier/courier-react-native 5.5.5 → 5.5.7

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.
@@ -15,7 +15,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
15
15
  import com.google.gson.GsonBuilder
16
16
 
17
17
  internal object Utils {
18
- val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.5.5")
18
+ val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.5.7")
19
19
  }
20
20
 
21
21
  internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
@@ -7,12 +7,19 @@
7
7
 
8
8
  @import Courier_iOS;
9
9
  #import "CourierReactNativeDelegate.h"
10
+ #import <React/RCTRootView.h>
11
+ #import <React/RCTBridge.h>
12
+ #import <React/RCTBridge+Private.h>
13
+ #import <React/RCTUtils.h>
14
+
10
15
  #pragma GCC diagnostic ignored "-Wprotocol"
11
16
  #pragma clang diagnostic ignored "-Wprotocol"
12
17
 
13
18
  @interface CourierReactNativeDelegate ()
14
19
 
15
20
  @property (nonatomic, assign) UNNotificationPresentationOptions notificationPresentationOptions;
21
+ @property (nonatomic, strong) NSDictionary *cachedMessage;
22
+ @property (nonatomic, assign) BOOL isReactNativeReady;
16
23
 
17
24
  @end
18
25
 
@@ -24,119 +31,119 @@ static NSString *const CourierForegroundOptionsDidChangeNotification = @"iosFore
24
31
  self = [super init];
25
32
 
26
33
  if (self) {
34
+
27
35
  // Set the user agent
28
- Courier.agent = [CourierAgent reactNativeIOS:@"5.5.5"];
36
+ Courier.agent = [CourierAgent reactNativeIOS:@"5.5.7"];
29
37
 
30
38
  // Register for remote notifications
31
39
  UIApplication *app = [UIApplication sharedApplication];
32
40
  [app registerForRemoteNotifications];
33
41
 
34
- // Register notification center changes
42
+ // Set notification center delegate
35
43
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
36
44
  center.delegate = self;
37
-
45
+
38
46
  [[NSNotificationCenter defaultCenter]
39
47
  addObserver:self
40
48
  selector:@selector(notificationPresentationOptionsUpdate:)
41
49
  name:CourierForegroundOptionsDidChangeNotification
42
- object:nil
43
- ];
50
+ object:nil];
51
+
52
+ [[NSNotificationCenter defaultCenter]
53
+ addObserver:self
54
+ selector:@selector(onBridgeWillReload)
55
+ name:RCTBridgeWillReloadNotification
56
+ object:nil];
57
+
58
+ [[NSNotificationCenter defaultCenter]
59
+ addObserver:self
60
+ selector:@selector(onReactUIReady:)
61
+ name:RCTContentDidAppearNotification
62
+ object:nil];
44
63
  }
45
64
 
46
65
  return self;
47
66
  }
48
67
 
49
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
68
+ // Called when React Native is loaded and ready
69
+ - (void)onReactUIReady:(__unused NSNotification *)note
50
70
  {
51
- // Killed-state launch support
52
- [self handleNotificationLaunchFromKilledState:launchOptions];
71
+ self.isReactNativeReady = YES;
53
72
 
54
- return YES;
73
+ // flush anything that was queued while RN was booting
74
+ if (self.cachedMessage) {
75
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:self.cachedMessage];
76
+ self.cachedMessage = nil;
77
+ }
55
78
  }
56
79
 
57
- - (void)notificationPresentationOptionsUpdate:(NSNotification *)notification
80
+ // Called when there is a reload to React Native
81
+ - (void)onBridgeWillReload
58
82
  {
59
- if ([[notification name] isEqualToString:CourierForegroundOptionsDidChangeNotification])
60
- {
61
- NSDictionary *userInfo = notification.userInfo;
62
- self.notificationPresentationOptions = ((NSNumber *)[userInfo objectForKey:@"options"]).unsignedIntegerValue;
63
- }
83
+ self.isReactNativeReady = NO;
64
84
  }
65
85
 
66
- /// Handles notification taps when the app launches from a killed state.
67
- /// Call this from AppDelegate's didFinishLaunchingWithOptions using UIApplicationLaunchOptionsRemoteNotificationKey.
68
- - (void)handleNotificationLaunchFromKilledState:(NSDictionary *)launchOptions
86
+ - (void)notificationPresentationOptionsUpdate:(NSNotification *)notification
69
87
  {
70
- NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
71
- if (userInfo) {
72
- // Track event
73
- [userInfo trackMessageWithEvent:CourierTrackingEventClicked completion:^(NSError * _Nullable error) {
74
- if (error) {
75
- NSLog(@"[Courier] Failed to track message click on cold start: %@", error.localizedDescription);
76
- }
77
- }];
78
-
79
- // Create temporary content for formatting
80
- UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
81
- content.userInfo = userInfo;
82
-
83
- dispatch_async(dispatch_get_main_queue(), ^{
84
- NSDictionary *formatted = [Courier formatPushNotificationWithContent:content];
85
- [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:formatted];
86
- });
87
- }
88
+ NSDictionary *userInfo = notification.userInfo;
89
+ self.notificationPresentationOptions = ((NSNumber *)[userInfo objectForKey:@"options"]).unsignedIntegerValue;
88
90
  }
89
91
 
90
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center
91
- willPresentNotification:(UNNotification *)notification
92
- withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
92
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
93
93
  {
94
- UNNotificationContent *content = notification.request.content;
94
+ UNNotificationContent *content = response.notification.request.content;
95
95
  NSDictionary *message = content.userInfo;
96
-
97
- [message trackMessageWithEvent:CourierTrackingEventDelivered completion:^(NSError * _Nullable error) {
96
+
97
+ [message trackMessageWithEvent:CourierTrackingEventClicked completion:^(NSError * _Nullable error) {
98
98
  if (error) {
99
- NSLog(@"Error tracking message: %@", error.localizedDescription);
99
+ NSLog(@"[Courier] Error tracking message: %@", error.localizedDescription);
100
100
  }
101
101
  }];
102
+
103
+ NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
102
104
 
103
105
  dispatch_async(dispatch_get_main_queue(), ^{
104
- NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
105
- [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered" object:nil userInfo:pushNotification];
106
- completionHandler(self.notificationPresentationOptions);
106
+ if (self.isReactNativeReady) {
107
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:pushNotification];
108
+ } else {
109
+ self.cachedMessage = pushNotification;
110
+ }
111
+ completionHandler();
107
112
  });
108
113
  }
109
114
 
110
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center
111
- didReceiveNotificationResponse:(UNNotificationResponse *)response
112
- withCompletionHandler:(void (^)(void))completionHandler
115
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
113
116
  {
114
- UNNotificationContent *content = response.notification.request.content;
117
+ UNNotificationContent *content = notification.request.content;
115
118
  NSDictionary *message = content.userInfo;
116
-
117
- [message trackMessageWithEvent:CourierTrackingEventClicked completion:^(NSError * _Nullable error) {
119
+
120
+ [message trackMessageWithEvent:CourierTrackingEventDelivered completion:^(NSError * _Nullable error) {
118
121
  if (error) {
119
- NSLog(@"Error tracking message: %@", error.localizedDescription);
122
+ NSLog(@"[Courier] Error tracking delivery: %@", error.localizedDescription);
120
123
  }
121
124
  }];
122
125
 
123
126
  dispatch_async(dispatch_get_main_queue(), ^{
124
127
  NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
125
- [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:pushNotification];
126
- completionHandler();
128
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered" object:nil userInfo:pushNotification];
129
+ completionHandler(self.notificationPresentationOptions);
127
130
  });
128
131
  }
129
132
 
130
- - (void)application:(UIApplication *)application
131
- didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
133
+ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
132
134
  {
133
- NSLog(@"Failed to register for remote notification token: %@", error.localizedDescription);
135
+ NSLog(@"[Courier] Failed to register for remote notifications: %@", error.localizedDescription);
134
136
  }
135
137
 
136
- - (void)application:(UIApplication *)application
137
- didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
138
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
138
139
  {
139
140
  [Courier setAPNSToken:deviceToken];
140
141
  }
141
142
 
143
+ - (void)dealloc
144
+ {
145
+ self.cachedMessage = nil;
146
+ self.isReactNativeReady = NO;
147
+ }
148
+
142
149
  @end
@@ -14,7 +14,7 @@ internal class CourierReactNativeEventEmitter: RCTEventEmitter {
14
14
 
15
15
  // Set the user agent
16
16
  // Used to know the platform performing requests
17
- Courier.agent = CourierAgent.reactNativeIOS("5.5.5")
17
+ Courier.agent = CourierAgent.reactNativeIOS("5.5.7")
18
18
 
19
19
  }
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-native",
3
- "version": "5.5.5",
3
+ "version": "5.5.7",
4
4
  "description": "Inbox, Push Notifications, and Preferences for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",