pushwoosh-react-native-plugin 2.0.0 → 2.2.17

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.
Files changed (66) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +135 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.yml +31 -0
  3. package/.github/ISSUE_TEMPLATE/question.yml +28 -0
  4. package/InlineInApp.js +71 -0
  5. package/README.md +35 -85
  6. package/docs/README.md +230 -11
  7. package/index.d.ts +91 -0
  8. package/index.js +265 -24
  9. package/package.json +12 -1
  10. package/pushwoosh-react-native-plugin.podspec +20 -0
  11. package/react-native.config.js +9 -0
  12. package/scripts/add_inbox_ios_resources.js +42 -0
  13. package/src/android/build.gradle +40 -10
  14. package/src/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  15. package/src/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  16. package/src/android/gradlew +160 -0
  17. package/src/android/gradlew.bat +90 -0
  18. package/src/android/src/main/AndroidManifest.xml +19 -54
  19. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/ConversionUtil.java +214 -148
  20. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/CustomFirebaseMessagingService.java +29 -0
  21. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/EventDispatcher.java +7 -6
  22. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/InboxUiStyleManager.java +162 -0
  23. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/InlineInAppManager.java +48 -0
  24. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshNotificationServiceExtension.java +44 -0
  25. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshPackage.java +4 -2
  26. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshPlugin.java +606 -393
  27. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/RCTInlineInAppView.java +75 -0
  28. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/internal/ReactNativePluginProvider.java +15 -0
  29. package/src/ios/PWAppDelegate.h +20 -0
  30. package/src/ios/PWGDPRManager.h +46 -0
  31. package/src/ios/PWIInboxStyle.h +122 -0
  32. package/src/ios/PWIInboxUI.h +39 -0
  33. package/src/ios/PWInAppManager.h +176 -0
  34. package/src/ios/PWInbox.h +147 -0
  35. package/src/ios/PWInlineInAppView.h +26 -0
  36. package/src/ios/PWLog.h +23 -0
  37. package/src/ios/PWMessaging.h +20 -0
  38. package/src/ios/PWNotificationExtensionManager.h +46 -0
  39. package/src/ios/PWRichMediaManager.h +123 -0
  40. package/src/ios/PWRichMediaStyle.h +122 -0
  41. package/src/ios/PushNotificationManager.h +234 -111
  42. package/src/ios/Pushwoosh.h +623 -0
  43. package/src/ios/PushwooshInboxBundle.bundle/Info.plist +0 -0
  44. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxAttachmentViewController.nib +0 -0
  45. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxMessageViewCell.nib +0 -0
  46. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxViewController.nib +0 -0
  47. package/src/ios/PushwooshInboxBundle.bundle/errorMessage@2x.png +0 -0
  48. package/src/ios/PushwooshInboxBundle.bundle/inbox_icon.png +0 -0
  49. package/src/ios/PushwooshInboxBundle.bundle/noMessage@2x.png +0 -0
  50. package/src/ios/PushwooshInboxBundle.bundle/unread.png +0 -0
  51. package/src/ios/PushwooshInboxUI.h +19 -0
  52. package/src/ios/PushwooshPlugin/PWEventDispatcher.h +1 -1
  53. package/src/ios/PushwooshPlugin/PWInlineInAppManager.h +17 -0
  54. package/src/ios/PushwooshPlugin/PWInlineInAppManager.m +54 -0
  55. package/src/ios/PushwooshPlugin/Pushwoosh.h +18 -3
  56. package/src/ios/PushwooshPlugin/Pushwoosh.m +532 -98
  57. package/src/ios/PushwooshPlugin.xcodeproj/project.pbxproj +27 -6
  58. package/src/ios/libPushwoosh.a +0 -0
  59. package/src/ios/libPushwooshInboxUI.a +0 -0
  60. package/.npmignore +0 -3
  61. package/src/android/.npmignore +0 -1
  62. package/src/android/pushwooshplugin.iml +0 -150
  63. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/NotificationReceiver.java +0 -42
  64. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PostEventActivity.java +0 -45
  65. package/src/ios/Pushwoosh.a +0 -0
  66. package/src/ios/PushwooshPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
@@ -6,173 +6,602 @@
6
6
 
7
7
  #import "Pushwoosh.h"
8
8
 
9
- #import "RCTUtils.h"
10
- #import "RCTBridge.h"
9
+ #import <React/RCTUtils.h>
10
+ #import <React/RCTBridge.h>
11
11
  #import "PWEventDispatcher.h"
12
- #import "RCTEventDispatcher.h"
12
+ #import <React/RCTEventDispatcher.h>
13
+ #import <React/RCTConvert.h>
14
+
15
+ #import <UserNotifications/UserNotifications.h>
13
16
 
14
17
  static id objectOrNull(id object) {
15
- if (!object) {
16
- return [NSNull null];
17
- }
18
- return object;
18
+ if (object) {
19
+ return object;
20
+ } else {
21
+ return [NSNull null];
22
+ }
19
23
  }
20
24
 
21
25
  static NSDictionary * gStartPushData = nil;
22
26
  static NSString * const kRegistrationSuccesEvent = @"PWRegistrationSuccess";
23
27
  static NSString * const kRegistrationErrorEvent = @"PWRegistrationError";
28
+ static NSString * const kPushReceivedEvent = @"PWPushReceived";
24
29
  static NSString * const kPushOpenEvent = @"PWPushOpen";
25
30
 
26
31
  static NSString * const kPushOpenJSEvent = @"pushOpened";
32
+ static NSString * const kPushReceivedJSEvent = @"pushReceived";
27
33
 
28
- @implementation Pushwoosh
34
+ @implementation PushwooshPlugin
29
35
 
30
36
  #pragma mark - Pushwoosh RCTBridgeModule
31
37
 
32
- RCT_EXPORT_MODULE();
38
+ RCT_EXPORT_MODULE(Pushwoosh);
39
+
40
+ - (dispatch_queue_t)methodQueue {
41
+ return dispatch_get_main_queue();
42
+ }
33
43
 
34
44
  RCT_EXPORT_METHOD(init:(NSDictionary*)config success:(RCTResponseSenderBlock)success error:(RCTResponseSenderBlock)error) {
35
- NSString *appCode = config[@"pw_appid"];
36
-
37
- if (!appCode || ![appCode isKindOfClass:[NSString class]]) {
38
- if (error) {
39
- error(@[ @"pw_appid is missing" ]);
40
- }
41
-
42
- return;
43
- }
44
-
45
- [PushNotificationManager initializeWithAppCode:appCode appName:nil];
46
- [[PushNotificationManager pushManager] sendAppOpen];
47
- [PushNotificationManager pushManager].delegate = self;
48
-
49
- if (gStartPushData) {
50
- [self sendJSEvent:kPushOpenJSEvent withArgs:gStartPushData];
51
- }
52
-
53
- if (success) {
54
- success(@[]);
55
- }
45
+ NSString *appCode = config[@"pw_appid"];
46
+ NSString *notificationHandling = config[@"pw_notification_handling"];
47
+
48
+ if (!appCode || ![appCode isKindOfClass:[NSString class]]) {
49
+ if (error) {
50
+ error(@[ @"pw_appid is missing" ]);
51
+ }
52
+
53
+ return;
54
+ }
55
+
56
+ NSString *proxyUrl = config[@"reverse_proxy_url"];
57
+ if (proxyUrl && ![proxyUrl isEqualToString:@""]) {
58
+ [[Pushwoosh sharedInstance] setReverseProxy:proxyUrl];
59
+ }
60
+
61
+ [PushNotificationManager initializeWithAppCode:appCode appName:nil];
62
+ [[PushNotificationManager pushManager] sendAppOpen];
63
+ [PushNotificationManager pushManager].delegate = self;
64
+
65
+ // We set Pushwoosh UNUserNotificationCenter delegate unless CUSTOM is specified in the config
66
+ if(![notificationHandling isEqualToString:@"CUSTOM"]) {
67
+ [UNUserNotificationCenter currentNotificationCenter].delegate = [PushNotificationManager pushManager].notificationCenterDelegate;
68
+ }
69
+
70
+ if (success) {
71
+ success(@[]);
72
+ }
73
+
74
+ if (gStartPushData) {
75
+ NSString *link = gStartPushData[@"l"];
76
+
77
+ //get deeplink from the payload and write it to the launchOptions for proper RCTLinking behavior
78
+ if (link) {
79
+ NSMutableDictionary *launchOptions = self.bridge.launchOptions.mutableCopy;
80
+ launchOptions[UIApplicationLaunchOptionsURLKey] = [NSURL URLWithString:link];
81
+ [self.bridge setValue:launchOptions forKey:@"launchOptions"];
82
+ }
83
+
84
+ [self sendJSEvent:kPushReceivedJSEvent withArgs:gStartPushData];
85
+ [self sendJSEvent:kPushOpenJSEvent withArgs:gStartPushData];
86
+ } else if([PushNotificationManager pushManager].launchNotification) {
87
+ [self sendJSEvent:kPushReceivedJSEvent withArgs:[PushNotificationManager pushManager].launchNotification];
88
+ [self sendJSEvent:kPushOpenJSEvent withArgs:[PushNotificationManager pushManager].launchNotification];
89
+ }
56
90
  }
57
91
 
58
92
  RCT_EXPORT_METHOD(register:(RCTResponseSenderBlock)success error:(RCTResponseSenderBlock)error) {
59
- [[PWEventDispatcher sharedDispatcher] subscribe:success toEvent:kRegistrationSuccesEvent];
60
- [[PWEventDispatcher sharedDispatcher] subscribe:error toEvent:kRegistrationErrorEvent];
61
-
62
- [[PushNotificationManager pushManager] registerForPushNotifications];
93
+ [[PWEventDispatcher sharedDispatcher] subscribe:success toEvent:kRegistrationSuccesEvent];
94
+ [[PWEventDispatcher sharedDispatcher] subscribe:error toEvent:kRegistrationErrorEvent];
95
+
96
+ [[PushNotificationManager pushManager] registerForPushNotifications];
63
97
  }
64
98
 
65
- RCT_EXPORT_METHOD(unregister:(RCTResponseSenderBlock)success error:(RCTResponseSenderBlock)error) {
66
- [[PushNotificationManager pushManager] unregisterForPushNotifications];
67
- if (success) {
68
- success(@[]);
69
- }
99
+ RCT_EXPORT_METHOD(unregister:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
100
+ [[PushNotificationManager pushManager] unregisterForPushNotificationsWithCompletion:^(NSError *error) {
101
+ if (!error && successCallback) {
102
+ successCallback(@[]);
103
+ }
104
+
105
+ if (error && errorCallback) {
106
+ errorCallback(@[ objectOrNull([error localizedDescription]) ]);
107
+ }
108
+ }];
70
109
  }
71
110
 
72
111
  RCT_EXPORT_METHOD(onPushOpen:(RCTResponseSenderBlock)callback) {
73
- [[PWEventDispatcher sharedDispatcher] subscribe:callback toEvent:kPushOpenEvent];
74
-
75
- if (gStartPushData) {
76
- NSDictionary *pushData = gStartPushData;
77
- gStartPushData = nil;
78
- [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(pushData) ]];
79
- }
112
+ [[PWEventDispatcher sharedDispatcher] subscribe:callback toEvent:kPushOpenEvent];
113
+
114
+ if (gStartPushData) {
115
+ NSDictionary *pushData = gStartPushData;
116
+ gStartPushData = nil;
117
+ [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(pushData) ]];
118
+ }
80
119
  }
81
120
 
121
+ RCT_EXPORT_METHOD(onPushReceived:(RCTResponseSenderBlock)callback) {
122
+ [[PWEventDispatcher sharedDispatcher] subscribe:callback toEvent:kPushReceivedEvent];
123
+
124
+ if (gStartPushData) {
125
+ NSDictionary *pushData = gStartPushData;
126
+ gStartPushData = nil;
127
+ [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushReceivedEvent withArgs:@[ objectOrNull(pushData) ]];
128
+ }
129
+ }
82
130
 
83
131
  RCT_EXPORT_METHOD(getHwid:(RCTResponseSenderBlock)callback) {
84
- if (callback) {
85
- callback(@[ [[PushNotificationManager pushManager] getHWID] ]);
86
- }
132
+ if (callback) {
133
+ callback(@[ [[PushNotificationManager pushManager] getHWID] ]);
134
+ }
87
135
  }
88
136
 
89
137
  RCT_EXPORT_METHOD(getPushToken:(RCTResponseSenderBlock)callback) {
90
- if (callback) {
91
- callback(@[ objectOrNull([[PushNotificationManager pushManager] getPushToken]) ]);
92
- }
138
+ if (callback) {
139
+ callback(@[ objectOrNull([[PushNotificationManager pushManager] getPushToken]) ]);
140
+ }
93
141
  }
94
142
 
95
143
  RCT_EXPORT_METHOD(setTags:(NSDictionary*)tags success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
96
- [[PushNotificationManager pushManager] setTags:tags withCompletion:^(NSError* error) {
97
- if (!error && successCallback) {
98
- successCallback(@[]);
99
- }
100
-
101
- if (error && errorCallback) {
102
- errorCallback(@[ objectOrNull([error localizedDescription]) ]);
103
- }
104
- }];
144
+ [[PushNotificationManager pushManager] setTags:tags withCompletion:^(NSError* error) {
145
+ if (!error && successCallback) {
146
+ successCallback(@[]);
147
+ }
148
+
149
+ if (error && errorCallback) {
150
+ errorCallback(@[ objectOrNull([error localizedDescription]) ]);
151
+ }
152
+ }];
105
153
  }
106
154
 
107
155
  RCT_EXPORT_METHOD(getTags:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
108
- [[PushNotificationManager pushManager] loadTags:^(NSDictionary* tags) {
109
- if (successCallback) {
110
- successCallback(@[ tags ]);
111
- }
112
- } error:^(NSError *error) {
113
- if (errorCallback) {
114
- errorCallback(@[ objectOrNull([error localizedDescription]) ]);
115
- }
116
- }];
156
+ [[PushNotificationManager pushManager] loadTags:^(NSDictionary* tags) {
157
+ if (successCallback) {
158
+ successCallback(@[ tags ]);
159
+ }
160
+ } error:^(NSError *error) {
161
+ if (errorCallback) {
162
+ errorCallback(@[ objectOrNull([error localizedDescription]) ]);
163
+ }
164
+ }];
117
165
  }
118
166
 
119
- RCT_EXPORT_METHOD(setUserId:(NSString*)userId) {
120
- [[PushNotificationManager pushManager] setUserId:userId];
167
+ RCT_EXPORT_METHOD(setShowPushnotificationAlert:(BOOL)showPushnotificationAlert) {
168
+ [[PushNotificationManager pushManager] setShowPushnotificationAlert:showPushnotificationAlert];
121
169
  }
122
170
 
123
- RCT_EXPORT_METHOD(postEvent:(NSString*)event withAttributes:(NSDictionary*)attributes) {
124
- [[PushNotificationManager pushManager] postEvent:event withAttributes:attributes];
171
+ RCT_EXPORT_METHOD(getShowPushnotificationAlert:(RCTResponseSenderBlock)callback) {
172
+ if(callback) {
173
+ callback(@[ @([PushNotificationManager pushManager].showPushnotificationAlert) ]);
174
+ }
175
+ }
176
+
177
+ RCT_EXPORT_METHOD(setUserId:(NSString*)userId) {
178
+ [[PWInAppManager sharedManager] setUserId:userId];
125
179
  }
126
180
 
127
- RCT_EXPORT_METHOD(startLocationTracking) {
128
- [[PushNotificationManager pushManager] startLocationTracking];
181
+ RCT_EXPORT_METHOD(setUserId:(NSString*)userId success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
182
+
183
+ [[PWInAppManager sharedManager] setUserId:userId completion:^(NSError *error) {
184
+ if (!error && successCallback) {
185
+ successCallback(@[]);
186
+ }
187
+
188
+ if (error && errorCallback) {
189
+ errorCallback(@[ objectOrNull([error localizedDescription]) ]);
190
+ }
191
+ }];
129
192
  }
130
193
 
131
- RCT_EXPORT_METHOD(stopLocationTracking) {
132
- [[PushNotificationManager pushManager] stopLocationTracking];
194
+ RCT_EXPORT_METHOD(postEvent:(NSString*)event withAttributes:(NSDictionary*)attributes) {
195
+ [[PWInAppManager sharedManager] postEvent:event withAttributes:attributes];
133
196
  }
134
197
 
135
198
  RCT_EXPORT_METHOD(setApplicationIconBadgeNumber:(nonnull NSNumber*)badgeNumber) {
136
- [UIApplication sharedApplication].applicationIconBadgeNumber = [badgeNumber integerValue];
199
+ dispatch_async(dispatch_get_main_queue(), ^{
200
+ [UIApplication sharedApplication].applicationIconBadgeNumber = [badgeNumber integerValue];
201
+ });
202
+ }
203
+
204
+ RCT_EXPORT_METHOD(setLanguage:(NSString *)language) {
205
+ [PushNotificationManager pushManager].language = language;
137
206
  }
138
207
 
139
208
  RCT_EXPORT_METHOD(getApplicationIconBadgeNumber:(RCTResponseSenderBlock)callback) {
140
- if(callback) {
141
- callback(@[ @([UIApplication sharedApplication].applicationIconBadgeNumber) ]);
142
- }
209
+ if(callback) {
210
+ dispatch_async(dispatch_get_main_queue(), ^{
211
+ callback(@[ @([UIApplication sharedApplication].applicationIconBadgeNumber) ]);
212
+ });
213
+ }
143
214
  }
144
215
 
145
216
  RCT_EXPORT_METHOD(addToApplicationIconBadgeNumber:(nonnull NSNumber*)badgeNumber) {
146
- [UIApplication sharedApplication].applicationIconBadgeNumber += [badgeNumber integerValue];
217
+ dispatch_async(dispatch_get_main_queue(), ^{
218
+ [UIApplication sharedApplication].applicationIconBadgeNumber += [badgeNumber integerValue];
219
+ });
220
+ }
221
+
222
+ RCT_EXPORT_METHOD(presentInboxUI:(NSDictionary *)styleDictionary) {
223
+ NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:@"PushwooshInboxBundle" ofType:@"bundle"];
224
+ if (![NSBundle bundleWithPath:resourceBundlePath]) {
225
+ NSLog(@"[Pushwoosh][presentInboxUI] Error: PushwooshInboxBundle.bundle not found. Please launch \"node node_modules/pushwoosh-react-native-plugin/scripts/add_inbox_ios_resources.js\" from project root directory or manually add node_modules/pushwoosh-react-native-plugin/src/ios/PushwooshInboxBundle.bundle to your project.");
226
+ } else {
227
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
228
+ PWIInboxViewController *inboxViewController = [PWIInboxUI createInboxControllerWithStyle:[self inboxStyleForDictionary:styleDictionary]];
229
+ inboxViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", @"Close") style:UIBarButtonItemStylePlain target:self action:@selector(closeInbox)];
230
+ [[PushwooshPlugin findRootViewController] presentViewController:[[UINavigationController alloc] initWithRootViewController:inboxViewController] animated:YES completion:nil];
231
+
232
+ __weak typeof (self) wself = self;
233
+ inboxViewController.onMessageClickBlock = ^(NSObject<PWInboxMessageProtocol> *message) {
234
+ if (message.type == PWInboxMessageTypeDeeplink) {
235
+ [wself closeInbox];
236
+ }
237
+ };
238
+ }];
239
+ }
240
+ }
241
+
242
+ RCT_EXPORT_METHOD(messagesWithNoActionPerformedCount:(RCTResponseSenderBlock)callback) {
243
+ [PWInbox messagesWithNoActionPerformedCountWithCompletion:^(NSInteger count, NSError *error) {
244
+ if (callback) {
245
+ callback(@[ @(count) ]);
246
+ }
247
+ }];
248
+ }
249
+
250
+ RCT_EXPORT_METHOD(unreadMessagesCount:(RCTResponseSenderBlock)callback) {
251
+ [PWInbox unreadMessagesCountWithCompletion:^(NSInteger count, NSError *error) {
252
+ if (callback) {
253
+ callback(@[ @(count) ]);
254
+ }
255
+ }];
256
+ }
257
+
258
+ RCT_EXPORT_METHOD(messagesCount:(RCTResponseSenderBlock)callback) {
259
+ [PWInbox messagesCountWithCompletion:^(NSInteger count, NSError *error) {
260
+ if (callback) {
261
+ callback(@[ @(count) ]);
262
+ }
263
+ }];
264
+ }
265
+
266
+ RCT_EXPORT_METHOD(loadMessages:(RCTResponseSenderBlock)success fail:(RCTResponseSenderBlock)fail) {
267
+ [PWInbox loadMessagesWithCompletion:^(NSArray<NSObject<PWInboxMessageProtocol> *> *messages, NSError *error) {
268
+ if (success) {
269
+ NSMutableArray* array = [[NSMutableArray alloc] init];
270
+ for (NSObject<PWInboxMessageProtocol>* message in messages) {
271
+ NSDictionary* dict = [self inboxMessageToDictionary:message];
272
+ [array addObject:dict];
273
+ }
274
+ success( @[ array ]);
275
+ } else if (error != nil && fail != nil) {
276
+ fail(@[ error ]);
277
+ }
278
+ }];
279
+ }
280
+
281
+ RCT_EXPORT_METHOD(readMessage:(NSString*)code) {
282
+ NSArray* arr = [NSArray arrayWithObject:code];
283
+ [PWInbox readMessagesWithCodes:arr];
284
+ }
285
+
286
+ RCT_EXPORT_METHOD(readMessages:(NSArray<NSString*>*)codes) {
287
+ [PWInbox readMessagesWithCodes:codes];
288
+ }
289
+
290
+ RCT_EXPORT_METHOD(deleteMessage:(NSString*)code) {
291
+ NSArray* arr = [NSArray arrayWithObject:code];
292
+ [PWInbox deleteMessagesWithCodes:arr];
147
293
  }
148
294
 
295
+ RCT_EXPORT_METHOD(deleteMessages:(NSArray<NSString*>*)codes) {
296
+ [PWInbox deleteMessagesWithCodes:codes];
297
+ }
298
+
299
+ RCT_EXPORT_METHOD(performAction:(NSString*)code) {
300
+ [PWInbox performActionForMessageWithCode:code];
301
+ }
302
+
303
+ - (NSDictionary*)inboxMessageToDictionary:(NSObject<PWInboxMessageProtocol>*) message {
304
+ NSMutableDictionary* dictionary = [[NSMutableDictionary alloc] init];
305
+ [dictionary setValue:@(message.type) forKey:@"type"];
306
+ [dictionary setValue:[self stringOrEmpty: message.imageUrl] forKey:@"imageUrl"];
307
+ [dictionary setValue:[self stringOrEmpty: message.code] forKey:@"code"];
308
+ [dictionary setValue:[self stringOrEmpty: message.title] forKey:@"title"];
309
+ [dictionary setValue:[self stringOrEmpty: message.message] forKey:@"message"];
310
+ [dictionary setValue:[self stringOrEmpty: [self dateToString:message.sendDate]] forKey:@"sendDate"];
311
+ [dictionary setValue:@(message.isRead) forKey:@"isRead"];
312
+ [dictionary setValue:@(message.isActionPerformed) forKey:@"isActionPerformed"];
313
+
314
+ NSDictionary* actionParams = [NSDictionary dictionaryWithDictionary:message.actionParams];
315
+ NSData* customData = [actionParams valueForKey:@"u"];
316
+ [dictionary setValue:customData forKey:@"customData"];
317
+
318
+ NSDictionary* result = [NSDictionary dictionaryWithDictionary:dictionary];
319
+ return result;
320
+ }
321
+
322
+ - (NSString *)stringOrEmpty:(NSString *)string {
323
+ return string != nil ? string : @"";
324
+ }
325
+
326
+ - (NSString*)dateToString:(NSDate*)date {
327
+ NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
328
+ [formatter setDateFormat:@"yyyy-MM-dd'T'H:mm:ssZ"];
329
+ return [formatter stringFromDate:date];
330
+ }
331
+
332
+ - (PWIInboxStyle *)inboxStyleForDictionary:(NSDictionary *)styleDictionary {
333
+ PWIInboxStyle *style = [PWIInboxStyle defaultStyle];
334
+
335
+ NSDictionary *defaultImageDict = styleDictionary[@"defaultImageIcon"];
336
+
337
+ if (defaultImageDict) {
338
+ style.defaultImageIcon = [RCTConvert UIImage:defaultImageDict];
339
+ }
340
+
341
+ NSString *dateFormat = styleDictionary[@"dateFormat"];
342
+
343
+ if (dateFormat) {
344
+ style.dateFormatterBlock = ^NSString *(NSDate *date, NSObject *owner) {
345
+ NSDateFormatter *formatter = [NSDateFormatter new];
346
+ formatter.dateFormat = dateFormat;
347
+ return [formatter stringFromDate:date];
348
+ };
349
+ }
350
+
351
+ NSDictionary *listErrorImageDict = styleDictionary[@"listErrorImage"];
352
+
353
+ if (listErrorImageDict) {
354
+ style.listErrorImage = [RCTConvert UIImage:listErrorImageDict];
355
+ }
356
+
357
+ NSDictionary *listEmptyImageDict = styleDictionary[@"listEmptyImage"];
358
+
359
+ if (listEmptyImageDict) {
360
+ style.listEmptyImage = [RCTConvert UIImage:listEmptyImageDict];
361
+ }
362
+
363
+ NSDictionary *unreadImageDict = styleDictionary[@"unreadImage"];
364
+
365
+ if (unreadImageDict) {
366
+ style.unreadImage = [RCTConvert UIImage:unreadImageDict];
367
+ }
368
+
369
+ NSString *listErrorMessage = styleDictionary[@"listErrorMessage"];
370
+
371
+ if (listErrorMessage) {
372
+ style.listErrorMessage = listErrorMessage;
373
+ }
374
+
375
+ NSString *listEmptyMessage = styleDictionary[@"listEmptyMessage"];
376
+
377
+ if (listEmptyMessage) {
378
+ style.listEmptyMessage = listEmptyMessage;
379
+ }
380
+
381
+ NSNumber *accentColorValue = styleDictionary[@"accentColor"];
382
+
383
+ if (accentColorValue) {
384
+ style.accentColor = [RCTConvert UIColor:accentColorValue];
385
+ }
386
+
387
+ NSNumber *defaultTextColorValue = styleDictionary[@"defaultTextColor"];
388
+
389
+ if (defaultTextColorValue) {
390
+ style.defaultTextColor = [RCTConvert UIColor:defaultTextColorValue];
391
+ }
392
+
393
+ NSNumber *backgroundColorValue = styleDictionary[@"backgroundColor"];
394
+
395
+ if (backgroundColorValue) {
396
+ style.backgroundColor = [RCTConvert UIColor:backgroundColorValue];
397
+ }
398
+
399
+ if (accentColorValue) {
400
+ style.accentColor = [RCTConvert UIColor:accentColorValue];
401
+ }
402
+
403
+ NSNumber *highlightColorValue = styleDictionary[@"highlightColor"];
404
+
405
+ if (highlightColorValue) {
406
+ style.selectionColor = [RCTConvert UIColor:highlightColorValue];
407
+ }
408
+
409
+ NSNumber *titleColorValue = styleDictionary[@"titleColor"];
410
+
411
+ if (titleColorValue) {
412
+ style.titleColor = [RCTConvert UIColor:titleColorValue];
413
+ }
414
+
415
+ NSNumber *descriptionColorValue = styleDictionary[@"descriptionColor"];
416
+
417
+ if (descriptionColorValue) {
418
+ style.descriptionColor = [RCTConvert UIColor:descriptionColorValue];
419
+ }
420
+
421
+ NSNumber *dateColorValue = styleDictionary[@"dateColor"];
422
+
423
+ if (dateColorValue) {
424
+ style.dateColor = [RCTConvert UIColor:dateColorValue];
425
+ }
426
+
427
+ NSNumber *dividerColorValue = styleDictionary[@"dividerColor"];
428
+
429
+ if (dividerColorValue) {
430
+ style.separatorColor = [RCTConvert UIColor:dividerColorValue];
431
+ }
432
+
433
+ NSNumber *barBackgroundColor = styleDictionary[@"barBackgroundColor"];
434
+
435
+ if (barBackgroundColor) {
436
+ style.barBackgroundColor = [RCTConvert UIColor:barBackgroundColor];
437
+ }
438
+
439
+ NSNumber *barAccentColor = styleDictionary[@"barAccentColor"];
440
+
441
+ if (barAccentColor) {
442
+ style.barAccentColor = [RCTConvert UIColor:barAccentColor];
443
+ }
444
+
445
+ NSNumber *barTextColor = styleDictionary[@"barTextColor"];
446
+
447
+ if (barTextColor) {
448
+ style.barTextColor = [RCTConvert UIColor:barTextColor];
449
+ }
450
+
451
+ return style;
452
+ }
453
+
454
+ - (void)closeInbox {
455
+ UIViewController *topViewController = [PushwooshPlugin findRootViewController];
456
+ if ([topViewController isKindOfClass:[UINavigationController class]] && [((UINavigationController*)topViewController).viewControllers.firstObject isKindOfClass:[PWIInboxViewController class]]) {
457
+ [topViewController dismissViewControllerAnimated:YES completion:nil];
458
+ }
459
+ }
460
+
461
+ + (UIViewController*)findRootViewController {
462
+ UIApplication *sharedApplication = [UIApplication valueForKey:@"sharedApplication"];
463
+ UIViewController *controller = sharedApplication.keyWindow.rootViewController;
464
+
465
+ while (controller.presentedViewController) {
466
+ controller = controller.presentedViewController;
467
+ }
468
+ return controller;
469
+ }
470
+
471
+ RCT_EXPORT_METHOD(showGDPRConsentUI) {
472
+ [[PWGDPRManager sharedManager] showGDPRConsentUI];
473
+ }
474
+
475
+ RCT_EXPORT_METHOD(showGDPRDeletionUI) {
476
+ [[PWGDPRManager sharedManager] showGDPRDeletionUI];
477
+ }
478
+
479
+ RCT_EXPORT_METHOD(isDeviceDataRemoved:(RCTResponseSenderBlock)callback) {
480
+ callback(@[@([PWGDPRManager sharedManager].isDeviceDataRemoved)]);
481
+ }
482
+
483
+ RCT_EXPORT_METHOD(isCommunicationEnabled:(RCTResponseSenderBlock)callback) {
484
+ callback(@[@([PWGDPRManager sharedManager].isCommunicationEnabled)]);
485
+ }
486
+
487
+ RCT_EXPORT_METHOD(isAvailableGDPR:(RCTResponseSenderBlock)callback) {
488
+ callback(@[@([PWGDPRManager sharedManager].isAvailable)]);
489
+ }
490
+
491
+ RCT_EXPORT_METHOD(setCommunicationEnabled:(BOOL)enabled success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
492
+ [[PWGDPRManager sharedManager] setCommunicationEnabled:enabled completion:^(NSError *error) {
493
+ if (error) {
494
+ if (errorCallback) {
495
+ errorCallback(@[error.localizedDescription]);
496
+ }
497
+ } else {
498
+ if (successCallback) {
499
+ successCallback(@[]);
500
+ }
501
+ }
502
+ }];
503
+ }
504
+
505
+ RCT_EXPORT_METHOD(removeAllDeviceData:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
506
+ [[PWGDPRManager sharedManager] removeAllDeviceDataWithCompletion:^(NSError *error) {
507
+ if (error) {
508
+ if (errorCallback) {
509
+ errorCallback(@[error.localizedDescription]);
510
+ }
511
+ } else {
512
+ if (successCallback) {
513
+ successCallback(@[]);
514
+ }
515
+ }
516
+ }];
517
+ }
518
+
519
+ RCT_EXPORT_METHOD(createLocalNotification:(NSDictionary *)params){
520
+ NSString *body = params[@"msg"];
521
+ NSUInteger delay = [params[@"seconds"] unsignedIntegerValue];
522
+ NSDictionary *userData = params[@"userData"];
523
+
524
+ [self sendLocalNotificationWithBody:body delay:delay userData:userData];
525
+ }
526
+
527
+ - (void)sendLocalNotificationWithBody:(NSString *)body delay:(NSUInteger)delay userData:(NSDictionary *)userData {
528
+ if (@available(iOS 10, *)) {
529
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
530
+ UNMutableNotificationContent *content = [UNMutableNotificationContent new];
531
+ content.body = body;
532
+ content.sound = [UNNotificationSound defaultSound];
533
+ content.userInfo = userData;
534
+ UNTimeIntervalNotificationTrigger *trigger = delay > 0 ? [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:delay repeats:NO] : nil;
535
+ NSString *identifier = @"LocalNotification";
536
+ UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier
537
+ content:content
538
+ trigger:trigger];
539
+
540
+ [center addNotificationRequest:request withCompletionHandler:^(NSError *_Nullable error) {
541
+ if (error != nil) {
542
+ NSLog(@"Something went wrong: %@", error);
543
+ }
544
+ }];
545
+ } else {
546
+ UILocalNotification *localNotification = [[UILocalNotification alloc] init];
547
+ localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:delay];
548
+ localNotification.alertBody = body;
549
+ localNotification.timeZone = [NSTimeZone defaultTimeZone];
550
+ localNotification.userInfo = userData;
551
+ [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
552
+ }
553
+ }
554
+
555
+ RCT_EXPORT_METHOD(clearLocalNotification){
556
+ if (@available(iOS 10, *)) {
557
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
558
+ [center removeAllDeliveredNotifications];
559
+ [center removeAllPendingNotificationRequests];
560
+ } else{
561
+ [[UIApplication sharedApplication] cancelAllLocalNotifications];
562
+ }
563
+ }
564
+
565
+ RCT_EXPORT_METHOD(clearNotificationCenter){
566
+ [PushNotificationManager clearNotificationCenter];
567
+ }
568
+
569
+
570
+ RCT_EXPORT_METHOD(enableHuaweiPushNotifications) {
571
+ // available in Android only
572
+ }
573
+
149
574
  #pragma mark - PushNotificationDelegate
150
575
 
151
576
  - (void)onDidRegisterForRemoteNotificationsWithDeviceToken:(NSString *)token {
152
- [[PWEventDispatcher sharedDispatcher] dispatchEvent:kRegistrationSuccesEvent withArgs:@[ objectOrNull(token) ]];
577
+ [[PWEventDispatcher sharedDispatcher] dispatchEvent:kRegistrationSuccesEvent withArgs:@[ objectOrNull(token) ]];
153
578
  }
154
579
 
155
580
  - (void)onDidFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
156
- [[PWEventDispatcher sharedDispatcher] dispatchEvent:kRegistrationErrorEvent withArgs:@[ objectOrNull([error localizedDescription]) ]];
581
+ [[PWEventDispatcher sharedDispatcher] dispatchEvent:kRegistrationErrorEvent withArgs:@[ objectOrNull([error localizedDescription]) ]];
582
+ }
583
+
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];
157
588
  }
158
589
 
159
590
  - (void)onPushAccepted:(PushNotificationManager *)manager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
160
- [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(pushNotification) ]];
161
-
162
- if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateBackground) {
163
- [self sendJSEvent:kPushOpenJSEvent withArgs:pushNotification];
164
- }
591
+ [[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(pushNotification) ]];
592
+
593
+ [self sendJSEvent:kPushOpenJSEvent withArgs:pushNotification];
165
594
  }
166
595
 
167
596
  #pragma mark - RCTEventEmitter
168
597
 
169
598
  - (void)sendJSEvent:(NSString*)event withArgs:(NSDictionary*)args {
170
- // [self sendEventWithName:event body:args];
171
- [self.bridge.eventDispatcher sendDeviceEventWithName:event body:args];
599
+ // [self sendEventWithName:event body:args];
600
+ [self.bridge.eventDispatcher sendDeviceEventWithName:event body:args];
172
601
  }
173
602
 
174
603
  - (NSArray<NSString *> *)supportedEvents {
175
- return @[ kPushOpenJSEvent ];
604
+ return @[ kPushOpenJSEvent ];
176
605
  }
177
606
 
178
607
  @end
@@ -180,18 +609,23 @@ RCT_EXPORT_METHOD(addToApplicationIconBadgeNumber:(nonnull NSNumber*)badgeNumber
180
609
  @implementation UIApplication (InternalPushRuntime)
181
610
 
182
611
  - (BOOL)pushwooshUseRuntimeMagic {
183
- return YES;
612
+ return YES;
184
613
  }
185
614
 
186
615
  // Just keep the launch notification until the module starts and callback functions initalizes
616
+ - (void)onPushReceived:(PushNotificationManager *)manager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
617
+ if (onStart) {
618
+ gStartPushData = pushNotification;
619
+ }
620
+ }
187
621
  - (void)onPushAccepted:(PushNotificationManager *)manager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
188
- if (onStart) {
189
- gStartPushData = pushNotification;
190
- }
622
+ if (onStart) {
623
+ gStartPushData = pushNotification;
624
+ }
191
625
  }
192
626
 
193
627
  - (NSObject<PushNotificationDelegate> *)getPushwooshDelegate {
194
- return (NSObject<PushNotificationDelegate> *)self;
628
+ return (NSObject<PushNotificationDelegate> *)self;
195
629
  }
196
630
 
197
631
  @end