pushwoosh-react-native-plugin 1.2.5 → 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.
- package/.github/ISSUE_TEMPLATE/bug_report.yml +135 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +31 -0
- package/.github/ISSUE_TEMPLATE/question.yml +28 -0
- package/InlineInApp.js +71 -0
- package/README.md +35 -85
- package/docs/README.md +230 -11
- package/index.d.ts +91 -0
- package/index.js +536 -154
- package/package.json +12 -1
- package/pushwoosh-react-native-plugin.podspec +20 -0
- package/react-native.config.js +9 -0
- package/scripts/add_inbox_ios_resources.js +42 -0
- package/src/android/build.gradle +40 -10
- package/src/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/src/android/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/src/android/gradlew +160 -0
- package/src/android/gradlew.bat +90 -0
- package/src/android/src/main/AndroidManifest.xml +19 -54
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/ConversionUtil.java +214 -148
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/CustomFirebaseMessagingService.java +29 -0
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/EventDispatcher.java +10 -2
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/InboxUiStyleManager.java +162 -0
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/InlineInAppManager.java +48 -0
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshNotificationServiceExtension.java +44 -0
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshPackage.java +4 -2
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshPlugin.java +608 -297
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/RCTInlineInAppView.java +75 -0
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/internal/ReactNativePluginProvider.java +15 -0
- package/src/ios/PWAppDelegate.h +20 -0
- package/src/ios/PWGDPRManager.h +46 -0
- package/src/ios/PWIInboxStyle.h +122 -0
- package/src/ios/PWIInboxUI.h +39 -0
- package/src/ios/PWInAppManager.h +176 -0
- package/src/ios/PWInbox.h +147 -0
- package/src/ios/PWInlineInAppView.h +26 -0
- package/src/ios/PWLog.h +23 -0
- package/src/ios/PWMessaging.h +20 -0
- package/src/ios/PWNotificationExtensionManager.h +46 -0
- package/src/ios/PWRichMediaManager.h +123 -0
- package/src/ios/PWRichMediaStyle.h +122 -0
- package/src/ios/PushNotificationManager.h +234 -111
- package/src/ios/Pushwoosh.h +623 -0
- package/src/ios/PushwooshInboxBundle.bundle/Info.plist +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/PWIInboxAttachmentViewController.nib +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/PWIInboxMessageViewCell.nib +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/PWIInboxViewController.nib +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/errorMessage@2x.png +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/inbox_icon.png +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/noMessage@2x.png +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/unread.png +0 -0
- package/src/ios/PushwooshInboxUI.h +19 -0
- package/src/ios/PushwooshPlugin/PWEventDispatcher.h +1 -1
- package/src/ios/PushwooshPlugin/PWInlineInAppManager.h +17 -0
- package/src/ios/PushwooshPlugin/PWInlineInAppManager.m +54 -0
- package/src/ios/PushwooshPlugin/Pushwoosh.h +19 -2
- package/src/ios/PushwooshPlugin/Pushwoosh.m +552 -75
- package/src/ios/PushwooshPlugin.xcodeproj/project.pbxproj +27 -6
- package/src/ios/libPushwoosh.a +0 -0
- package/src/ios/libPushwooshInboxUI.a +0 -0
- package/.npmignore +0 -3
- package/src/android/.npmignore +0 -1
- package/src/android/pushwooshplugin.iml +0 -145
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/NotificationReceiver.java +0 -42
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PostEventActivity.java +0 -45
- package/src/ios/Pushwoosh.a +0 -0
- package/src/ios/PushwooshPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
|
@@ -6,130 +6,602 @@
|
|
|
6
6
|
|
|
7
7
|
#import "Pushwoosh.h"
|
|
8
8
|
|
|
9
|
-
#import
|
|
10
|
-
#import
|
|
9
|
+
#import <React/RCTUtils.h>
|
|
10
|
+
#import <React/RCTBridge.h>
|
|
11
11
|
#import "PWEventDispatcher.h"
|
|
12
|
+
#import <React/RCTEventDispatcher.h>
|
|
13
|
+
#import <React/RCTConvert.h>
|
|
14
|
+
|
|
15
|
+
#import <UserNotifications/UserNotifications.h>
|
|
12
16
|
|
|
13
17
|
static id objectOrNull(id object) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
if (object) {
|
|
19
|
+
return object;
|
|
20
|
+
} else {
|
|
21
|
+
return [NSNull null];
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
static NSDictionary * gStartPushData = nil;
|
|
21
26
|
static NSString * const kRegistrationSuccesEvent = @"PWRegistrationSuccess";
|
|
22
27
|
static NSString * const kRegistrationErrorEvent = @"PWRegistrationError";
|
|
28
|
+
static NSString * const kPushReceivedEvent = @"PWPushReceived";
|
|
23
29
|
static NSString * const kPushOpenEvent = @"PWPushOpen";
|
|
24
30
|
|
|
25
|
-
@
|
|
31
|
+
static NSString * const kPushOpenJSEvent = @"pushOpened";
|
|
32
|
+
static NSString * const kPushReceivedJSEvent = @"pushReceived";
|
|
33
|
+
|
|
34
|
+
@implementation PushwooshPlugin
|
|
26
35
|
|
|
27
36
|
#pragma mark - Pushwoosh RCTBridgeModule
|
|
28
37
|
|
|
29
|
-
RCT_EXPORT_MODULE();
|
|
38
|
+
RCT_EXPORT_MODULE(Pushwoosh);
|
|
39
|
+
|
|
40
|
+
- (dispatch_queue_t)methodQueue {
|
|
41
|
+
return dispatch_get_main_queue();
|
|
42
|
+
}
|
|
30
43
|
|
|
31
44
|
RCT_EXPORT_METHOD(init:(NSDictionary*)config success:(RCTResponseSenderBlock)success error:(RCTResponseSenderBlock)error) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
}
|
|
49
90
|
}
|
|
50
91
|
|
|
51
92
|
RCT_EXPORT_METHOD(register:(RCTResponseSenderBlock)success error:(RCTResponseSenderBlock)error) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
93
|
+
[[PWEventDispatcher sharedDispatcher] subscribe:success toEvent:kRegistrationSuccesEvent];
|
|
94
|
+
[[PWEventDispatcher sharedDispatcher] subscribe:error toEvent:kRegistrationErrorEvent];
|
|
95
|
+
|
|
96
|
+
[[PushNotificationManager pushManager] registerForPushNotifications];
|
|
56
97
|
}
|
|
57
98
|
|
|
58
|
-
RCT_EXPORT_METHOD(unregister:(RCTResponseSenderBlock)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
}];
|
|
63
109
|
}
|
|
64
110
|
|
|
65
111
|
RCT_EXPORT_METHOD(onPushOpen:(RCTResponseSenderBlock)callback) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
+
}
|
|
73
119
|
}
|
|
74
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
|
+
}
|
|
75
130
|
|
|
76
131
|
RCT_EXPORT_METHOD(getHwid:(RCTResponseSenderBlock)callback) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
132
|
+
if (callback) {
|
|
133
|
+
callback(@[ [[PushNotificationManager pushManager] getHWID] ]);
|
|
134
|
+
}
|
|
80
135
|
}
|
|
81
136
|
|
|
82
137
|
RCT_EXPORT_METHOD(getPushToken:(RCTResponseSenderBlock)callback) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
138
|
+
if (callback) {
|
|
139
|
+
callback(@[ objectOrNull([[PushNotificationManager pushManager] getPushToken]) ]);
|
|
140
|
+
}
|
|
86
141
|
}
|
|
87
142
|
|
|
88
143
|
RCT_EXPORT_METHOD(setTags:(NSDictionary*)tags success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
+
}];
|
|
98
153
|
}
|
|
99
154
|
|
|
100
155
|
RCT_EXPORT_METHOD(getTags:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
+
}];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
RCT_EXPORT_METHOD(setShowPushnotificationAlert:(BOOL)showPushnotificationAlert) {
|
|
168
|
+
[[PushNotificationManager pushManager] setShowPushnotificationAlert:showPushnotificationAlert];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
RCT_EXPORT_METHOD(getShowPushnotificationAlert:(RCTResponseSenderBlock)callback) {
|
|
172
|
+
if(callback) {
|
|
173
|
+
callback(@[ @([PushNotificationManager pushManager].showPushnotificationAlert) ]);
|
|
174
|
+
}
|
|
110
175
|
}
|
|
111
176
|
|
|
112
177
|
RCT_EXPORT_METHOD(setUserId:(NSString*)userId) {
|
|
113
|
-
|
|
178
|
+
[[PWInAppManager sharedManager] setUserId:userId];
|
|
179
|
+
}
|
|
180
|
+
|
|
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
|
+
}];
|
|
114
192
|
}
|
|
115
193
|
|
|
116
194
|
RCT_EXPORT_METHOD(postEvent:(NSString*)event withAttributes:(NSDictionary*)attributes) {
|
|
117
|
-
|
|
195
|
+
[[PWInAppManager sharedManager] postEvent:event withAttributes:attributes];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
RCT_EXPORT_METHOD(setApplicationIconBadgeNumber:(nonnull NSNumber*)badgeNumber) {
|
|
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;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
RCT_EXPORT_METHOD(getApplicationIconBadgeNumber:(RCTResponseSenderBlock)callback) {
|
|
209
|
+
if(callback) {
|
|
210
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
211
|
+
callback(@[ @([UIApplication sharedApplication].applicationIconBadgeNumber) ]);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
RCT_EXPORT_METHOD(addToApplicationIconBadgeNumber:(nonnull NSNumber*)badgeNumber) {
|
|
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];
|
|
293
|
+
}
|
|
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;
|
|
118
320
|
}
|
|
119
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
|
+
}
|
|
120
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
|
+
|
|
121
574
|
#pragma mark - PushNotificationDelegate
|
|
122
575
|
|
|
123
576
|
- (void)onDidRegisterForRemoteNotificationsWithDeviceToken:(NSString *)token {
|
|
124
|
-
|
|
577
|
+
[[PWEventDispatcher sharedDispatcher] dispatchEvent:kRegistrationSuccesEvent withArgs:@[ objectOrNull(token) ]];
|
|
125
578
|
}
|
|
126
579
|
|
|
127
580
|
- (void)onDidFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
|
|
128
|
-
|
|
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];
|
|
129
588
|
}
|
|
130
589
|
|
|
131
590
|
- (void)onPushAccepted:(PushNotificationManager *)manager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
|
|
132
|
-
|
|
591
|
+
[[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(pushNotification) ]];
|
|
592
|
+
|
|
593
|
+
[self sendJSEvent:kPushOpenJSEvent withArgs:pushNotification];
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
#pragma mark - RCTEventEmitter
|
|
597
|
+
|
|
598
|
+
- (void)sendJSEvent:(NSString*)event withArgs:(NSDictionary*)args {
|
|
599
|
+
// [self sendEventWithName:event body:args];
|
|
600
|
+
[self.bridge.eventDispatcher sendDeviceEventWithName:event body:args];
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
604
|
+
return @[ kPushOpenJSEvent ];
|
|
133
605
|
}
|
|
134
606
|
|
|
135
607
|
@end
|
|
@@ -137,18 +609,23 @@ RCT_EXPORT_METHOD(postEvent:(NSString*)event withAttributes:(NSDictionary*)attri
|
|
|
137
609
|
@implementation UIApplication (InternalPushRuntime)
|
|
138
610
|
|
|
139
611
|
- (BOOL)pushwooshUseRuntimeMagic {
|
|
140
|
-
|
|
612
|
+
return YES;
|
|
141
613
|
}
|
|
142
614
|
|
|
143
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
|
+
}
|
|
144
621
|
- (void)onPushAccepted:(PushNotificationManager *)manager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
622
|
+
if (onStart) {
|
|
623
|
+
gStartPushData = pushNotification;
|
|
624
|
+
}
|
|
148
625
|
}
|
|
149
626
|
|
|
150
627
|
- (NSObject<PushNotificationDelegate> *)getPushwooshDelegate {
|
|
151
|
-
|
|
628
|
+
return (NSObject<PushNotificationDelegate> *)self;
|
|
152
629
|
}
|
|
153
630
|
|
|
154
631
|
@end
|