pushwoosh-cordova-plugin 6.0.1 → 6.1.1

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 (78) hide show
  1. package/{MIT-LICENSE.txt → LICENSE.md} +0 -0
  2. package/README.md +20 -32
  3. package/README_PGB.md +32 -0
  4. package/package.json +1 -1
  5. package/package_pgb.json +29 -0
  6. package/plugin.xml +71 -82
  7. package/src/android/src/com/pushwoosh/plugin/internal/PhonegapPluginProvider.java +22 -0
  8. package/src/android/src/com/pushwoosh/plugin/pushnotifications/CustomFirebaseMessagingService.java +29 -0
  9. package/src/android/src/com/pushwoosh/plugin/pushnotifications/InboxUiStyleManager.java +136 -0
  10. package/src/android/src/com/pushwoosh/plugin/pushnotifications/PushNotifications.java +365 -387
  11. package/src/android/src/com/pushwoosh/plugin/pushnotifications/PushwooshNotificationServiceExtension.java +38 -0
  12. package/src/ios/PWBackward.h +25 -0
  13. package/src/ios/PWBackward.m +53 -0
  14. package/src/ios/PushNotification.m +409 -147
  15. package/src/ios/Pushwoosh.framework/Modules/module.modulemap +6 -0
  16. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWAppDelegate.h +20 -0
  17. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWGDPRManager.h +46 -0
  18. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInAppManager.h +174 -0
  19. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInbox.h +147 -0
  20. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInlineInAppView.h +26 -0
  21. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWLog.h +23 -0
  22. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWMessaging.h +20 -0
  23. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWNotificationExtensionManager.h +33 -0
  24. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWRichMediaManager.h +118 -0
  25. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWRichMediaStyle.h +122 -0
  26. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PushNotificationManager.h +263 -151
  27. package/src/ios/Pushwoosh.framework/Versions/A/Headers/Pushwoosh.h +525 -0
  28. package/src/ios/Pushwoosh.framework/Versions/A/libPushwoosh.a +0 -0
  29. package/src/ios/PushwooshInboxBundle.bundle/Info.plist +0 -0
  30. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxAttachmentViewController.nib +0 -0
  31. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxMessageViewCell.nib +0 -0
  32. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxViewController.nib +0 -0
  33. package/src/ios/PushwooshInboxBundle.bundle/errorMessage@2x.png +0 -0
  34. package/src/ios/PushwooshInboxBundle.bundle/inbox_icon.png +0 -0
  35. package/src/ios/PushwooshInboxBundle.bundle/noMessage@2x.png +0 -0
  36. package/src/ios/PushwooshInboxBundle.bundle/unread.png +0 -0
  37. package/src/ios/PushwooshInboxUI.framework/Modules/module.modulemap +6 -0
  38. package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PWIInboxStyle.h +122 -0
  39. package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PWIInboxUI.h +39 -0
  40. package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PushwooshInboxUI.h +19 -0
  41. package/src/ios/PushwooshInboxUI.framework/Versions/A/libPushwooshInboxUI.a +0 -0
  42. package/src/windows/PushSDK/Newtonsoft.Json.dll +0 -0
  43. package/src/windows/PushSDK/PushSDK.winmd +0 -0
  44. package/src/windows/PushwooshPluginProxy.js +88 -74
  45. package/src/wp8/PushNotification.cs +14 -0
  46. package/src/wp8/PushSDK/PushSDK.dll +0 -0
  47. package/www/PushNotification.js +179 -45
  48. package/Documentation/files/PushNotification-js.html +0 -157
  49. package/Documentation/index/Classes.html +0 -33
  50. package/Documentation/index/Functions.html +0 -61
  51. package/Documentation/index/General.html +0 -65
  52. package/Documentation/index.html +0 -1
  53. package/Documentation/javascript/main.js +0 -841
  54. package/Documentation/javascript/prettify.js +0 -1526
  55. package/Documentation/javascript/searchdata.js +0 -92
  56. package/Documentation/search/ClassesP.html +0 -20
  57. package/Documentation/search/FunctionsA.html +0 -20
  58. package/Documentation/search/FunctionsC.html +0 -20
  59. package/Documentation/search/FunctionsG.html +0 -20
  60. package/Documentation/search/FunctionsO.html +0 -20
  61. package/Documentation/search/FunctionsP.html +0 -20
  62. package/Documentation/search/FunctionsR.html +0 -20
  63. package/Documentation/search/FunctionsS.html +0 -20
  64. package/Documentation/search/FunctionsU.html +0 -20
  65. package/Documentation/search/GeneralA.html +0 -20
  66. package/Documentation/search/GeneralC.html +0 -20
  67. package/Documentation/search/GeneralF.html +0 -20
  68. package/Documentation/search/GeneralG.html +0 -20
  69. package/Documentation/search/GeneralO.html +0 -20
  70. package/Documentation/search/GeneralP.html +0 -20
  71. package/Documentation/search/GeneralR.html +0 -20
  72. package/Documentation/search/GeneralS.html +0 -20
  73. package/Documentation/search/GeneralU.html +0 -20
  74. package/Documentation/search/NoResults.html +0 -15
  75. package/Documentation/styles/main.css +0 -828
  76. package/VERSION.md +0 -132
  77. package/push.gradle +0 -21
  78. package/src/ios/Pushwoosh.framework/Versions/A/Pushwoosh +0 -0
@@ -12,17 +12,43 @@
12
12
 
13
13
  #import "PushNotification.h"
14
14
  #import "PWLog.h"
15
- #import <CoreLocation/CoreLocation.h>
15
+ #import "PushwooshInboxUI.h"
16
+ #import "PWGDPRManager.h"
17
+ #import "PWInAppManager.h"
18
+ #import "PWBackward.h"
19
+ #import "Pushwoosh.h"
20
+
16
21
  #import "AppDelegate.h"
17
22
 
23
+ #import <UserNotifications/UserNotifications.h>
24
+
18
25
  #import <objc/runtime.h>
19
26
 
27
+
20
28
  #define WRITEJS(VAL) [NSString stringWithFormat:@"setTimeout(function() { %@; }, 0);", VAL]
21
29
 
22
- @interface PushNotification()
30
+
31
+ @interface PWCommonJSBridge: NSObject <PWJavaScriptInterface>
32
+
33
+ @property (nonatomic) CDVPlugin *plugin;
34
+
35
+ @end
36
+
37
+
38
+ @implementation PWCommonJSBridge
39
+
40
+ - (void)callFunction:(NSString *)functionName :(NSString *)parameters {
41
+ NSString *function = parameters != nil ? [NSString stringWithFormat:@"%@(%@)", functionName, parameters] : [NSString stringWithFormat:@"%@()", functionName];
42
+ [_plugin.webViewEngine evaluateJavaScript:function completionHandler:nil];
43
+ }
44
+
45
+ @end
46
+
47
+ @interface PushNotification() <PWMessagingDelegate>
23
48
 
24
49
  @property (nonatomic, retain) NSMutableDictionary *callbackIds;
25
50
  @property (nonatomic, retain) PushNotificationManager *pushManager;
51
+ @property (nonatomic, retain) Pushwoosh *pushwoosh;
26
52
  @property (nonatomic, copy) NSDictionary *startPushData;
27
53
  @property (nonatomic, assign) BOOL startPushCleared;
28
54
  @property (nonatomic, assign) BOOL deviceReady;
@@ -31,7 +57,21 @@
31
57
 
32
58
  @end
33
59
 
34
- void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, const char * signature);
60
+ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, const char * signature) {
61
+ Method method = nil;
62
+ method = class_getInstanceMethod(class, fromChange);
63
+
64
+ if (method) {
65
+ //method exists add a new method and swap with original
66
+ class_addMethod(class, toChange, impl, signature);
67
+ method_exchangeImplementations(class_getInstanceMethod(class, fromChange), class_getInstanceMethod(class, toChange));
68
+ } else {
69
+ //just add as orignal method
70
+ class_addMethod(class, fromChange, impl, signature);
71
+ }
72
+ }
73
+
74
+ static PushNotification *pw_PushNotificationPlugin;
35
75
 
36
76
  #pragma clang diagnostic push
37
77
  #pragma clang diagnostic ignored "-Wincomplete-implementation"
@@ -40,31 +80,44 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
40
80
 
41
81
  #pragma clang diagnostic pop
42
82
 
83
+ - (void)pluginInitialize {
84
+ [super pluginInitialize];
85
+ pw_PushNotificationPlugin = self;
86
+ }
87
+
43
88
  - (NSMutableDictionary *)callbackIds {
44
- if (_callbackIds == nil) {
45
- _callbackIds = [[NSMutableDictionary alloc] init];
46
- }
47
- return _callbackIds;
89
+ if (_callbackIds == nil) {
90
+ _callbackIds = [[NSMutableDictionary alloc] init];
91
+ }
92
+ return _callbackIds;
48
93
  }
49
94
 
50
95
  - (PushNotificationManager *)pushManager {
51
- if (_pushManager == nil) {
52
- _pushManager = [PushNotificationManager pushManager];
53
- _pushManager.delegate = self;
54
- }
55
- return _pushManager;
96
+ if (_pushManager == nil) {
97
+ _pushManager = [PushNotificationManager pushManager];
98
+ _pushManager.delegate = self;
99
+ }
100
+ return _pushManager;
101
+ }
102
+
103
+ - (Pushwoosh *)pushwoosh {
104
+ if (_pushwoosh == nil) {
105
+ _pushwoosh = [Pushwoosh sharedInstance];
106
+ _pushwoosh.delegate = self;
107
+ }
108
+ return _pushwoosh;
56
109
  }
57
110
 
58
111
  - (void)getPushToken:(CDVInvokedUrlCommand *)command {
59
- NSString *token = [[PushNotificationManager pushManager] getPushToken];
60
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:token];
61
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
112
+ NSString *token = [[PushNotificationManager pushManager] getPushToken];
113
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:token];
114
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
62
115
  }
63
116
 
64
117
  - (void)getPushwooshHWID:(CDVInvokedUrlCommand *)command {
65
- NSString *token = [[PushNotificationManager pushManager] getHWID];
66
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:token];
67
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
118
+ NSString *token = [[PushNotificationManager pushManager] getHWID];
119
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:token];
120
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
68
121
  }
69
122
 
70
123
  - (void)onDeviceReady:(CDVInvokedUrlCommand *)command {
@@ -87,31 +140,64 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
87
140
  else {
88
141
  [PushNotificationManager initializeWithAppCode:appid appName:appname];
89
142
  }
90
-
143
+
144
+ [UNUserNotificationCenter currentNotificationCenter].delegate = [PushNotificationManager pushManager].notificationCenterDelegate;
91
145
  [self.pushManager sendAppOpen];
92
146
 
93
147
  NSString * alertTypeString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"Pushwoosh_ALERT_TYPE"];
94
148
  if([alertTypeString isKindOfClass:[NSString class]] && [alertTypeString isEqualToString:@"NONE"]) {
95
149
  self.pushManager.showPushnotificationAlert = NO;
96
150
  }
151
+
152
+ _deviceReady = YES;
97
153
 
98
- AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
99
- PushNotification *pushHandler = [delegate.viewController getCommandInstance:@"PushNotification"];
100
- if (pushHandler.startPushData && !_deviceReady) {
101
- [self dispatchPush:pushHandler.startPushData];
154
+ if (self.pushwoosh.launchNotification) {
155
+ NSDictionary *notification = [self createNotificationDataForPush:self.pushwoosh.launchNotification onStart:YES];
156
+ [self dispatchPushReceive:notification];
157
+ [self dispatchPushAccept:notification];
102
158
  }
103
159
 
104
- _deviceReady = YES;
105
-
106
160
  [[NSUserDefaults standardUserDefaults] synchronize];
107
161
  }
108
162
 
109
- - (void)dispatchPush:(NSDictionary *)pushData {
110
- NSData *json = [NSJSONSerialization dataWithJSONObject:pushData options:NSJSONWritingPrettyPrinted error:nil];
111
- NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
112
-
113
- NSString *jsStatement = [NSString stringWithFormat: @"cordova.require(\"pushwoosh-cordova-plugin.PushNotification\").notificationCallback(%@);", jsonString];
114
- [self.commandDelegate evalJs:WRITEJS(jsStatement)];
163
+ // Authorization options in addition to UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay. Should be called before registering for pushes
164
+ - (void)additionalAuthorizationOptions:(CDVInvokedUrlCommand *)command {
165
+ NSDictionary *options = [command.arguments firstObject];
166
+ NSString* critical = options[@"UNAuthorizationOptionCriticalAlert"];
167
+ NSString* provisional = options[@"UNAuthorizationOptionProvisional"];
168
+ NSString* providesSettings = options[@"UNAuthorizationOptionProvidesAppNotificationSettings"];
169
+
170
+ UNAuthorizationOptions authOptions = 0;
171
+ if (@available(iOS 12.0, *)) {
172
+ if (critical) {
173
+ authOptions |= UNAuthorizationOptionCriticalAlert;
174
+ }
175
+ if (provisional) {
176
+ authOptions |= UNAuthorizationOptionProvisional;
177
+ }
178
+ if (providesSettings) {
179
+ authOptions |= UNAuthorizationOptionProvidesAppNotificationSettings;
180
+ }
181
+ [Pushwoosh sharedInstance].additionalAuthorizationOptions = authOptions;
182
+ }
183
+ }
184
+
185
+ - (void)dispatchPushReceive:(NSDictionary *)pushData {
186
+ NSData *json = [NSJSONSerialization dataWithJSONObject:pushData options:NSJSONWritingPrettyPrinted error:nil];
187
+ NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
188
+
189
+ NSString *pushReceiveJsStatement = [NSString stringWithFormat: @"cordova.require(\"pushwoosh-cordova-plugin.PushNotification\").pushReceivedCallback(%@);", jsonString];
190
+
191
+ [self.commandDelegate evalJs:WRITEJS(pushReceiveJsStatement)];
192
+ }
193
+
194
+ - (void)dispatchPushAccept:(NSDictionary *)pushData {
195
+ NSData *json = [NSJSONSerialization dataWithJSONObject:pushData options:NSJSONWritingPrettyPrinted error:nil];
196
+ NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
197
+
198
+ NSString *pushOpenJsStatement = [NSString stringWithFormat: @"cordova.require(\"pushwoosh-cordova-plugin.PushNotification\").notificationCallback(%@);", jsonString];
199
+
200
+ [self.commandDelegate evalJs:WRITEJS(pushOpenJsStatement)];
115
201
  }
116
202
 
117
203
  - (void)registerDevice:(CDVInvokedUrlCommand *)command {
@@ -128,23 +214,30 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
128
214
  }
129
215
 
130
216
  - (void)unregisterDevice:(CDVInvokedUrlCommand *)command {
131
- [[PushNotificationManager pushManager] unregisterForPushNotifications];
132
-
133
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
134
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
217
+ self.callbackIds[@"unregisterDevice"] = command.callbackId;
218
+
219
+ [[PushNotificationManager pushManager] unregisterForPushNotificationsWithCompletion:^(NSError *error) {
220
+ if (!error) {
221
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
222
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"unregisterDevice"]];
223
+ } else {
224
+ NSMutableDictionary *results = [NSMutableDictionary dictionary];
225
+ results[@"error"] = [NSString stringWithFormat:@"%@", error];
226
+
227
+ CDVPluginResult *pluginResult =
228
+ [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:results];
229
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"unregisterDevice"]];
230
+ }
231
+ }];
135
232
  }
136
233
 
137
234
  - (void)startBeaconPushes:(CDVInvokedUrlCommand *)command {
138
- [[PushNotificationManager pushManager] startBeaconTracking];
139
-
140
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
235
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:@{ @"error" : @"Beacon tracking is not supported" }];
141
236
  [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
142
237
  }
143
238
 
144
239
  - (void)stopBeaconPushes:(CDVInvokedUrlCommand *)command {
145
- [[PushNotificationManager pushManager] stopBeaconTracking];
146
-
147
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
240
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:@{ @"error" : @"Beacon tracking is not supported" }];
148
241
  [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
149
242
  }
150
243
 
@@ -177,102 +270,119 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
177
270
  }];
178
271
  }
179
272
 
180
- - (void)sendLocation:(CDVInvokedUrlCommand *)command {
181
- NSNumber *lat = command.arguments[0][@"lat"];
182
- NSNumber *lon = command.arguments[0][@"lon"];
183
- CLLocation *location = [[CLLocation alloc] initWithLatitude:[lat doubleValue] longitude:[lon doubleValue]];
184
- [[PushNotificationManager pushManager] sendLocation:location];
185
-
186
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
187
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
188
- }
189
-
190
- - (void)startLocationTracking:(CDVInvokedUrlCommand *)command {
191
- [[PushNotificationManager pushManager] startLocationTracking];
192
-
193
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
194
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
195
- }
196
-
197
- - (void)stopLocationTracking:(CDVInvokedUrlCommand *)command {
198
- [[PushNotificationManager pushManager] stopLocationTracking];
199
-
200
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
201
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
273
+ - (void)createLocalNotification:(CDVInvokedUrlCommand *)command {
274
+ NSDictionary *params = command.arguments[0];
275
+ NSString *body = params[@"msg"];
276
+ NSUInteger delay = [params[@"seconds"] unsignedIntegerValue];
277
+ NSDictionary *userData = params[@"userData"];
278
+
279
+ [self sendLocalNotificationWithBody:body delay:delay userData:userData];
280
+
281
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
282
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
283
+ }
284
+
285
+ - (void)sendLocalNotificationWithBody:(NSString *)body delay:(NSUInteger)delay userData:(NSDictionary *)userData {
286
+ if (@available(iOS 10, *)) {
287
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
288
+ UNMutableNotificationContent *content = [UNMutableNotificationContent new];
289
+ content.body = body;
290
+ content.sound = [UNNotificationSound defaultSound];
291
+ content.userInfo = userData;
292
+ UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:delay repeats:NO];
293
+ NSString *identifier = @"LocalNotification";
294
+ UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier
295
+ content:content
296
+ trigger:trigger];
297
+
298
+ [center addNotificationRequest:request withCompletionHandler:^(NSError *_Nullable error) {
299
+ if (error != nil) {
300
+ NSLog(@"Something went wrong: %@", error);
301
+ }
302
+ }];
303
+ } else {
304
+ UILocalNotification *localNotification = [[UILocalNotification alloc] init];
305
+ localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:delay];
306
+ localNotification.alertBody = body;
307
+ localNotification.timeZone = [NSTimeZone defaultTimeZone];
308
+ localNotification.userInfo = userData;
309
+ [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
310
+ }
202
311
  }
203
312
 
204
313
  - (void)onDidRegisterForRemoteNotificationsWithDeviceToken:(NSString *)token {
205
- NSMutableDictionary *results = [PushNotificationManager getRemoteNotificationStatus];
206
- results[@"pushToken"] = token;
207
-
208
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:results];
209
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"registerDevice"]];
314
+ if (self.callbackIds[@"registerDevice"]) {
315
+ NSMutableDictionary *results = [PushNotificationManager getRemoteNotificationStatus];
316
+ results[@"pushToken"] = token;
317
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:results];
318
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"registerDevice"]];
319
+ }
210
320
  }
211
321
 
212
322
  - (void)onDidFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
213
- NSMutableDictionary *results = [NSMutableDictionary dictionary];
214
- results[@"error"] = [NSString stringWithFormat:@"%@", error];
215
-
216
- CDVPluginResult *pluginResult =
217
- [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:results];
218
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"registerDevice"]];
219
- }
220
-
221
- - (void)onPushAccepted:(PushNotificationManager *)manager
222
- withNotification:(NSDictionary *)pushNotification
223
- onStart:(BOOL)onStart {
224
-
225
- if (!onStart && !_deviceReady) {
226
- PWLogWarn(@"PUSHWOOSH WARNING: push notification onStart is false, but onDeviceReady has not been called. Did you "
227
- @"forget to call onDeviceReady?");
228
- }
229
-
230
- NSMutableDictionary *notification = [NSMutableDictionary new];
231
-
232
- notification[@"onStart"] = @(onStart);
233
-
234
- BOOL isForegound = [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
235
- notification[@"foreground"] = @(isForegound);
236
-
237
- id alert = pushNotification[@"aps"][@"alert"];
238
- NSString *message = alert;
239
- if ([alert isKindOfClass:[NSDictionary class]]) {
240
- message = alert[@"body"];
241
- }
242
-
243
- if (message) {
244
- notification[@"message"] = message;
245
- }
246
-
247
- //pase JSON string in custom data to JSON Object
248
- NSString *userdata = pushNotification[@"u"];
249
-
250
- if (userdata) {
251
- id parsedData = [NSJSONSerialization JSONObjectWithData:[userdata dataUsingEncoding:NSUTF8StringEncoding]
252
- options:NSJSONReadingMutableContainers
253
- error:nil];
254
-
255
- if (parsedData) {
256
- notification[@"userdata"] = parsedData;
257
- }
258
- }
259
-
260
- notification[@"ios"] = pushNotification;
261
-
262
- PWLogDebug(@"Notification opened: %@", notification);
263
-
264
- if (onStart) {
265
- //keep the start push
266
- AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
267
- PushNotification *pushHandler = [delegate.viewController getCommandInstance:@"PushNotification"];
268
- pushHandler.startPushData = notification;
269
- pushHandler.startPushCleared = NO;
323
+ if (self.callbackIds[@"registerDevice"]) {
324
+ NSMutableDictionary *results = [NSMutableDictionary dictionary];
325
+ results[@"error"] = [NSString stringWithFormat:@"%@", error];
326
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:results];
327
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"registerDevice"]];
270
328
  }
329
+ }
271
330
 
272
- if (_deviceReady) {
273
- //send it to the webview
274
- [self dispatchPush:notification];
275
- }
331
+ - (NSDictionary *)createNotificationDataForPush:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
332
+ if (!onStart && !_deviceReady) {
333
+ PWLogWarn(@"PUSHWOOSH WARNING: onStart is false, but onDeviceReady has not been called. Did you "
334
+ @"forget to call onDeviceReady?");
335
+ }
336
+
337
+ NSMutableDictionary *notification = [NSMutableDictionary new];
338
+
339
+ notification[@"onStart"] = @(onStart);
340
+
341
+ BOOL isForegound = [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
342
+ notification[@"foreground"] = @(isForegound);
343
+
344
+ id alert = pushNotification[@"aps"][@"alert"];
345
+ NSString *message = alert;
346
+ if ([alert isKindOfClass:[NSDictionary class]]) {
347
+ message = alert[@"body"];
348
+ }
349
+
350
+ if (message) {
351
+ notification[@"message"] = message;
352
+ }
353
+
354
+ NSDictionary *userdata = [[PushNotificationManager pushManager] getCustomPushDataAsNSDict:pushNotification];
355
+ if (userdata) {
356
+ notification[@"userdata"] = userdata;
357
+ }
358
+
359
+ notification[@"ios"] = pushNotification;
360
+
361
+ PWLogDebug(@"Notification opened: %@", notification);
362
+
363
+ if (onStart) {
364
+ //keep the start push
365
+ self.startPushData = notification;
366
+ self.startPushCleared = NO;
367
+ }
368
+
369
+ return notification;
370
+ }
371
+
372
+ - (void)onPushReceived:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
373
+ if (_deviceReady) {
374
+ NSDictionary *notification = [self createNotificationDataForPush:pushNotification onStart:onStart];
375
+ //send it to the webview
376
+ [self dispatchPushReceive:notification];
377
+ }
378
+ }
379
+
380
+ - (void)onPushAccepted:(PushNotificationManager *)manager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
381
+ if (_deviceReady) {
382
+ NSDictionary *notification = [self createNotificationDataForPush:pushNotification onStart:onStart];
383
+ //send it to the webview
384
+ [self dispatchPushAccept:notification];
385
+ }
276
386
  }
277
387
 
278
388
  - (void)getRemoteNotificationStatus:(CDVInvokedUrlCommand *)command {
@@ -291,10 +401,10 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
291
401
  }
292
402
 
293
403
  - (void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
294
- NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
295
-
296
- CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:badge];
297
- [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
404
+ NSInteger badge = [UIApplication sharedApplication].applicationIconBadgeNumber;
405
+
406
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:(int)badge];
407
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
298
408
  }
299
409
 
300
410
  - (void)addToApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
@@ -306,7 +416,7 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
306
416
  }
307
417
 
308
418
  - (void)cancelAllLocalNotifications:(CDVInvokedUrlCommand *)command {
309
- [[UIApplication sharedApplication] cancelAllLocalNotifications];
419
+ [UIApplication sharedApplication].scheduledLocalNotifications = @[];
310
420
 
311
421
  CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
312
422
  [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
@@ -327,19 +437,177 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
327
437
  }
328
438
 
329
439
  - (void)setUserId:(CDVInvokedUrlCommand *)command {
330
- NSString *userId = command.arguments[0];
331
- [self.pushManager setUserId:userId];
440
+ NSString *userId = command.arguments[0];
441
+ [[PWInAppManager sharedManager] setUserId:userId];
332
442
  }
333
443
 
334
444
  - (void) postEvent:(CDVInvokedUrlCommand *)command {
335
- NSString *event = command.arguments[0];
336
- NSDictionary *attributes = command.arguments[1];
337
- [self.pushManager postEvent:event withAttributes:attributes];
445
+ NSString *event = command.arguments[0];
446
+ NSDictionary *attributes = command.arguments[1];
447
+ [[PWInAppManager sharedManager] postEvent:event withAttributes:attributes];
448
+ }
449
+
450
+ - (void)addJavaScriptInterface:(CDVInvokedUrlCommand *)command {
451
+ NSString *name = command.arguments[0];
452
+ PWCommonJSBridge *bridge = [PWCommonJSBridge new];
453
+ bridge.plugin = self;
454
+ [[PWInAppManager sharedManager] addJavascriptInterface:bridge withName:name];
455
+ }
456
+
457
+ - (void)showGDPRConsentUI:(CDVInvokedUrlCommand *)command {
458
+ [[PWGDPRManager sharedManager] showGDPRConsentUI];
459
+
460
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
461
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
462
+ }
463
+
464
+ - (void)showGDPRDeletionUI:(CDVInvokedUrlCommand *)command {
465
+ [[PWGDPRManager sharedManager] showGDPRDeletionUI];
466
+
467
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
468
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
469
+ }
470
+
471
+ - (void)setCommunicationEnabled:(CDVInvokedUrlCommand *)command {
472
+ self.callbackIds[@"setCommunicationEnabled"] = command.callbackId;
473
+
474
+ NSNumber *enabledObject = [command.arguments firstObject];
475
+
476
+ BOOL enabled = [enabledObject boolValue];
477
+
478
+ [[PWGDPRManager sharedManager] setCommunicationEnabled:enabled completion:^(NSError *error) {
479
+ if (!error) {
480
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
481
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"setCommunicationEnabled"]];
482
+ } else {
483
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.localizedDescription];
484
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"setCommunicationEnabled"]];
485
+ }
486
+ }];
487
+ }
488
+
489
+ - (void)removeAllDeviceData:(CDVInvokedUrlCommand *)command {
490
+ self.callbackIds[@"removeAllDeviceData"] = command.callbackId;
491
+
492
+ [[PWGDPRManager sharedManager] removeAllDeviceDataWithCompletion:^(NSError *error) {
493
+ if (!error) {
494
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
495
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"removeAllDeviceData"]];
496
+ } else {
497
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.localizedDescription];
498
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"removeAllDeviceData"]];
499
+ }
500
+ }];
501
+ }
502
+
503
+ - (void)isCommunicationEnabled:(CDVInvokedUrlCommand *)command {
504
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:[[PWGDPRManager sharedManager] isCommunicationEnabled]];
505
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
506
+ }
507
+
508
+ - (void)isDeviceDataRemoved:(CDVInvokedUrlCommand *)command {
509
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:[[PWGDPRManager sharedManager] isDeviceDataRemoved]];
510
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
511
+ }
512
+
513
+ - (void)isAvailableGDPR:(CDVInvokedUrlCommand *)command {
514
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:[[PWGDPRManager sharedManager] isAvailable]];
515
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
516
+ }
517
+
518
+ - (void)enableHuaweiPushNotifications:(CDVInvokedUrlCommand *)command {
519
+ // Stub
520
+
521
+ CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
522
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
523
+ }
524
+
525
+ - (UIImage *)imageFromInboxStyleDict:(NSDictionary *)dict forKey:(NSString *)key {
526
+ NSObject *object = dict[key];
527
+ if (object != nil && [object isKindOfClass:[NSString class]]) {
528
+ return [UIImage imageWithContentsOfFile:[self.commandDelegate pathForResource:(NSString *)object]];
529
+ }
530
+ return nil;
531
+ }
532
+
533
+ - (UIColor *)colorFromInboxStyleDict:(NSDictionary *)dict forKey:(NSString *)key {
534
+ NSObject *object = dict[key];
535
+ if (object != nil && [object isKindOfClass:[NSString class]]) {
536
+ return [PWBackward colorFromColorString:(NSString *)object cordovaViewController:((CDVViewController *)self.viewController)];
537
+ }
538
+ return nil;
539
+ }
540
+
541
+ - (NSString *)stringFromInboxStyleDict:(NSDictionary *)dict forKey:(NSString *)key {
542
+ NSObject *object = dict[key];
543
+ if (object != nil && [object isKindOfClass:[NSString class]]) {
544
+ return (NSString *)object;
545
+ }
546
+ return nil;
547
+ }
548
+
549
+ - (NSString *(^)(NSDate *date, NSObject *owner))dateFormatterBlockFromInboxStyleDict:(NSDictionary *)dict forKey:(NSString *)key {
550
+ NSObject *object = dict[key];
551
+ if (object != nil && [object isKindOfClass:[NSString class]]) {
552
+ NSDateFormatter *formatter = [NSDateFormatter new];
553
+ formatter.dateFormat = (NSString*)object;
554
+ return ^NSString *(NSDate *date, NSObject *owner) {
555
+ return [formatter stringFromDate:date];
556
+ };
557
+ }
558
+ return nil;
559
+ }
560
+
561
+ - (PWIInboxStyle *)inboxStyleForDictionary:(NSDictionary *)styleDictionary {
562
+ PWIInboxStyle *style = [PWIInboxStyle defaultStyle];
563
+
564
+ if (![self.viewController isKindOfClass:[CDVViewController class]] || ![styleDictionary isKindOfClass:[NSDictionary class]]) {
565
+ return style;
566
+ }
567
+
568
+ #define styleValue(prop, key, type) { id val = [self type##FromInboxStyleDict:styleDictionary forKey:key]; if (val != nil) prop = val; }
569
+
570
+ styleValue(style.defaultImageIcon, @"defaultImageIcon", image);
571
+ styleValue(style.dateFormatterBlock, @"dateFormat", dateFormatterBlock);
572
+ styleValue(style.listErrorMessage, @"listErrorMessage", string);
573
+ styleValue(style.listEmptyMessage, @"listEmptyMessage", string);
574
+ styleValue(style.accentColor, @"accentColor", color);
575
+ styleValue(style.defaultTextColor, @"defaultTextColor", color);
576
+ styleValue(style.backgroundColor, @"backgroundColor", color);
577
+ styleValue(style.selectionColor, @"highlightColor", color);
578
+ styleValue(style.titleColor, @"titleColor", color);
579
+ styleValue(style.descriptionColor, @"descriptionColor", color);
580
+ styleValue(style.dateColor, @"dateColor", color);
581
+ styleValue(style.separatorColor, @"dividerColor", color);
582
+
583
+ styleValue(style.listErrorImage, @"listErrorImage", image);
584
+ styleValue(style.listEmptyImage, @"listEmptyImage", image);
585
+ styleValue(style.unreadImage, @"unreadImage", image);
586
+
587
+ styleValue(style.barTextColor, @"barTextColor", color);
588
+ styleValue(style.barAccentColor, @"barAccentColor", color);
589
+ styleValue(style.barBackgroundColor, @"barBackgroundColor", color);
590
+ styleValue(style.barTitle, @"barTitle", string);
591
+ #undef styleValue
592
+
593
+ return style;
594
+ }
595
+
596
+ - (void)presentInboxUI:(CDVInvokedUrlCommand *)command {
597
+ NSDictionary *styleDictionary = [command.arguments firstObject];
598
+ UIViewController *inboxViewController = [PWIInboxUI createInboxControllerWithStyle:[self inboxStyleForDictionary:styleDictionary]];
599
+ inboxViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", @"Close") style:UIBarButtonItemStylePlain target:self action:@selector(closeInbox)];
600
+ [self.viewController presentViewController:[[UINavigationController alloc] initWithRootViewController:inboxViewController] animated:YES completion:nil];
601
+ }
602
+
603
+ - (void)closeInbox {
604
+ if ([self.viewController.presentedViewController isKindOfClass:[UINavigationController class]] && [((UINavigationController*)self.viewController.presentedViewController).viewControllers.firstObject isKindOfClass:[PWIInboxViewController class]]) {
605
+ [self.viewController dismissViewControllerAnimated:YES completion:nil];
606
+ }
338
607
  }
339
608
 
340
609
  BOOL pwplugin_didRegisterUserNotificationSettings(id self, SEL _cmd, id application, id notificationSettings) {
341
- AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
342
- PushNotification *pushHandler = [delegate.viewController getCommandInstance:@"PushNotification"];
610
+ PushNotification *pushHandler = pw_PushNotificationPlugin;
343
611
 
344
612
  UIUserNotificationSettings *settings = notificationSettings;
345
613
 
@@ -402,10 +670,4 @@ BOOL pwplugin_didRegisterUserNotificationSettings(id self, SEL _cmd, id applicat
402
670
  return YES;
403
671
  }
404
672
 
405
- - (NSObject<PushNotificationDelegate> *)getPushwooshDelegate {
406
- AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
407
- PushNotification *pushHandler = [delegate.viewController getCommandInstance:@"PushNotification"];
408
- return pushHandler;
409
- }
410
-
411
673
  @end