@trycourier/courier-react-native 5.5.5 → 5.5.6

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.6")
19
19
  }
20
20
 
21
21
  internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
@@ -7,12 +7,18 @@
7
7
 
8
8
  @import Courier_iOS;
9
9
  #import "CourierReactNativeDelegate.h"
10
+ #import <React/RCTBridge.h>
11
+ #import <React/RCTBridge+Private.h>
12
+ #import <React/RCTUtils.h>
13
+
10
14
  #pragma GCC diagnostic ignored "-Wprotocol"
11
15
  #pragma clang diagnostic ignored "-Wprotocol"
12
16
 
13
17
  @interface CourierReactNativeDelegate ()
14
18
 
15
19
  @property (nonatomic, assign) UNNotificationPresentationOptions notificationPresentationOptions;
20
+ @property (nonatomic, strong) NSDictionary *pendingNotificationClick;
21
+ @property (nonatomic, assign) BOOL isReactNativeReady;
16
22
 
17
23
  @end
18
24
 
@@ -25,112 +31,111 @@ static NSString *const CourierForegroundOptionsDidChangeNotification = @"iosFore
25
31
 
26
32
  if (self) {
27
33
  // Set the user agent
28
- Courier.agent = [CourierAgent reactNativeIOS:@"5.5.5"];
34
+ Courier.agent = [CourierAgent reactNativeIOS:@"5.5.6"];
29
35
 
30
36
  // Register for remote notifications
31
37
  UIApplication *app = [UIApplication sharedApplication];
32
38
  [app registerForRemoteNotifications];
33
39
 
34
- // Register notification center changes
40
+ // Set notification center delegate
35
41
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
36
42
  center.delegate = self;
37
43
 
44
+ // Detect JS bridge load
45
+ self.isReactNativeReady = [self detectIfBridgeIsReady];
46
+
47
+ [[NSNotificationCenter defaultCenter]
48
+ addObserver:self
49
+ selector:@selector(onJavaScriptDidLoad:)
50
+ name:RCTJavaScriptDidLoadNotification
51
+ object:nil];
52
+
38
53
  [[NSNotificationCenter defaultCenter]
39
54
  addObserver:self
40
55
  selector:@selector(notificationPresentationOptionsUpdate:)
41
56
  name:CourierForegroundOptionsDidChangeNotification
42
- object:nil
43
- ];
57
+ object:nil];
44
58
  }
45
59
 
46
60
  return self;
47
61
  }
48
62
 
49
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
50
- {
51
- // Killed-state launch support
52
- [self handleNotificationLaunchFromKilledState:launchOptions];
53
-
54
- return YES;
63
+ - (BOOL)detectIfBridgeIsReady {
64
+ // RCTBridge currentBridge is non-nil only after JS is loaded
65
+ return [RCTBridge currentBridge] != nil;
55
66
  }
56
67
 
57
68
  - (void)notificationPresentationOptionsUpdate:(NSNotification *)notification
58
69
  {
59
- if ([[notification name] isEqualToString:CourierForegroundOptionsDidChangeNotification])
60
- {
61
- NSDictionary *userInfo = notification.userInfo;
62
- self.notificationPresentationOptions = ((NSNumber *)[userInfo objectForKey:@"options"]).unsignedIntegerValue;
63
- }
70
+ NSDictionary *userInfo = notification.userInfo;
71
+ self.notificationPresentationOptions = ((NSNumber *)[userInfo objectForKey:@"options"]).unsignedIntegerValue;
64
72
  }
65
73
 
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
74
+ - (void)onJavaScriptDidLoad:(NSNotification *)notification
69
75
  {
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
- });
76
+ self.isReactNativeReady = YES;
77
+
78
+ if (self.pendingNotificationClick) {
79
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked"
80
+ object:nil
81
+ userInfo:self.pendingNotificationClick];
82
+ self.pendingNotificationClick = nil;
87
83
  }
88
84
  }
89
85
 
90
86
  - (void)userNotificationCenter:(UNUserNotificationCenter *)center
91
- willPresentNotification:(UNNotification *)notification
92
- withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
87
+ didReceiveNotificationResponse:(UNNotificationResponse *)response
88
+ withCompletionHandler:(void (^)(void))completionHandler
93
89
  {
94
- UNNotificationContent *content = notification.request.content;
90
+ UNNotificationContent *content = response.notification.request.content;
95
91
  NSDictionary *message = content.userInfo;
96
-
97
- [message trackMessageWithEvent:CourierTrackingEventDelivered completion:^(NSError * _Nullable error) {
92
+
93
+ [message trackMessageWithEvent:CourierTrackingEventClicked completion:^(NSError * _Nullable error) {
98
94
  if (error) {
99
- NSLog(@"Error tracking message: %@", error.localizedDescription);
95
+ NSLog(@"[Courier] Error tracking message: %@", error.localizedDescription);
100
96
  }
101
97
  }];
102
-
98
+
99
+ NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
100
+
103
101
  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);
102
+ if (self.isReactNativeReady) {
103
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked"
104
+ object:nil
105
+ userInfo:pushNotification];
106
+ } else {
107
+ self.pendingNotificationClick = pushNotification;
108
+ }
109
+ completionHandler();
107
110
  });
108
111
  }
109
112
 
110
113
  - (void)userNotificationCenter:(UNUserNotificationCenter *)center
111
- didReceiveNotificationResponse:(UNNotificationResponse *)response
112
- withCompletionHandler:(void (^)(void))completionHandler
114
+ willPresentNotification:(UNNotification *)notification
115
+ 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"
129
+ object:nil
130
+ userInfo:pushNotification];
131
+ completionHandler(self.notificationPresentationOptions);
127
132
  });
128
133
  }
129
134
 
130
135
  - (void)application:(UIApplication *)application
131
136
  didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
132
137
  {
133
- NSLog(@"Failed to register for remote notification token: %@", error.localizedDescription);
138
+ NSLog(@"[Courier] Failed to register for remote notifications: %@", error.localizedDescription);
134
139
  }
135
140
 
136
141
  - (void)application:(UIApplication *)application
@@ -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.6")
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.6",
4
4
  "description": "Inbox, Push Notifications, and Preferences for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",