@trycourier/courier-react-native 5.5.3 → 5.5.5

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.
@@ -22,7 +22,7 @@ class CourierSystemModule(reactContext: ReactApplicationContext): ReactNativeMod
22
22
 
23
23
  init {
24
24
 
25
- // Handle delivered messages on the main thread
25
+ // Listen to push notification events
26
26
  Courier.shared.onPushNotificationEvent { event ->
27
27
  when (event.trackingEvent) {
28
28
  CLICKED -> postPushNotificationJavascriptEvent(CourierEvents.Push.CLICKED_EVENT, event.remoteMessage)
@@ -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.3")
18
+ val COURIER_AGENT = CourierAgent.ReactNativeAndroid(version = "5.5.5")
19
19
  }
20
20
 
21
21
  internal fun ReactContext.sendEvent(eventName: String, value: Any?) {
@@ -2,7 +2,7 @@
2
2
  // CourierReactNativeDelegate.m
3
3
  // courier-react-native
4
4
  //
5
- // Created by Michael Miller on 10/7/22.
5
+ // Created by https://github.com/mikemilla on 10/7/22.
6
6
  //
7
7
 
8
8
  @import Courier_iOS;
@@ -12,21 +12,20 @@
12
12
 
13
13
  @interface CourierReactNativeDelegate ()
14
14
 
15
- @property (nonatomic, copy) NSString *iosForegroundNotificationPresentationOptions;
16
15
  @property (nonatomic, assign) UNNotificationPresentationOptions notificationPresentationOptions;
17
16
 
18
17
  @end
19
18
 
20
19
  @implementation CourierReactNativeDelegate
21
20
 
22
- - (id) init {
23
-
21
+ static NSString *const CourierForegroundOptionsDidChangeNotification = @"iosForegroundNotificationPresentationOptions";
22
+
23
+ - (id)init {
24
24
  self = [super init];
25
25
 
26
26
  if (self) {
27
-
28
27
  // Set the user agent
29
- Courier.agent = [CourierAgent reactNativeIOS:@"5.5.3"];
28
+ Courier.agent = [CourierAgent reactNativeIOS:@"5.5.5"];
30
29
 
31
30
  // Register for remote notifications
32
31
  UIApplication *app = [UIApplication sharedApplication];
@@ -39,28 +38,59 @@
39
38
  [[NSNotificationCenter defaultCenter]
40
39
  addObserver:self
41
40
  selector:@selector(notificationPresentationOptionsUpdate:)
42
- name:_iosForegroundNotificationPresentationOptions
41
+ name:CourierForegroundOptionsDidChangeNotification
43
42
  object:nil
44
43
  ];
45
-
46
44
  }
47
45
 
48
- return(self);
49
-
46
+ return self;
47
+ }
48
+
49
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
50
+ {
51
+ // Killed-state launch support
52
+ [self handleNotificationLaunchFromKilledState:launchOptions];
53
+
54
+ return YES;
50
55
  }
51
56
 
52
- - (void) notificationPresentationOptionsUpdate:(NSNotification *) notification
57
+ - (void)notificationPresentationOptionsUpdate:(NSNotification *)notification
53
58
  {
54
- if ([[notification name] isEqualToString:_iosForegroundNotificationPresentationOptions])
59
+ if ([[notification name] isEqualToString:CourierForegroundOptionsDidChangeNotification])
55
60
  {
56
61
  NSDictionary *userInfo = notification.userInfo;
57
- _notificationPresentationOptions = ((NSNumber *) [userInfo objectForKey:@"options"]).unsignedIntegerValue;
62
+ self.notificationPresentationOptions = ((NSNumber *)[userInfo objectForKey:@"options"]).unsignedIntegerValue;
58
63
  }
59
64
  }
60
65
 
61
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
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
69
+ {
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
+ }
89
+
90
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
91
+ willPresentNotification:(UNNotification *)notification
92
+ withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
62
93
  {
63
-
64
94
  UNNotificationContent *content = notification.request.content;
65
95
  NSDictionary *message = content.userInfo;
66
96
 
@@ -71,19 +101,16 @@
71
101
  }];
72
102
 
73
103
  dispatch_async(dispatch_get_main_queue(), ^{
74
-
75
104
  NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
76
105
  [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered" object:nil userInfo:pushNotification];
77
-
78
- completionHandler(self->_notificationPresentationOptions);
79
-
106
+ completionHandler(self.notificationPresentationOptions);
80
107
  });
81
-
82
108
  }
83
109
 
84
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
110
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
111
+ didReceiveNotificationResponse:(UNNotificationResponse *)response
112
+ withCompletionHandler:(void (^)(void))completionHandler
85
113
  {
86
-
87
114
  UNNotificationContent *content = response.notification.request.content;
88
115
  NSDictionary *message = content.userInfo;
89
116
 
@@ -94,22 +121,20 @@
94
121
  }];
95
122
 
96
123
  dispatch_async(dispatch_get_main_queue(), ^{
97
-
98
124
  NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
99
125
  [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:pushNotification];
100
-
101
126
  completionHandler();
102
-
103
127
  });
104
-
105
128
  }
106
129
 
107
- - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
130
+ - (void)application:(UIApplication *)application
131
+ didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
108
132
  {
109
- NSLog(@"Failed to rgister for remote notification token: %@", error.localizedDescription);
133
+ NSLog(@"Failed to register for remote notification token: %@", error.localizedDescription);
110
134
  }
111
135
 
112
- - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
136
+ - (void)application:(UIApplication *)application
137
+ didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
113
138
  {
114
139
  [Courier setAPNSToken:deviceToken];
115
140
  }
@@ -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.3")
17
+ Courier.agent = CourierAgent.reactNativeIOS("5.5.5")
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.3",
3
+ "version": "5.5.5",
4
4
  "description": "Inbox, Push Notifications, and Preferences for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",