pushwoosh-cordova-plugin 6.1.0 → 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.
- package/{MIT-LICENSE.txt → LICENSE.md} +0 -0
- package/README.md +20 -32
- package/README_PGB.md +32 -0
- package/package.json +1 -1
- package/package_pgb.json +29 -0
- package/plugin.xml +71 -85
- package/src/android/src/com/pushwoosh/plugin/internal/PhonegapPluginProvider.java +22 -0
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/CustomFirebaseMessagingService.java +29 -0
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/InboxUiStyleManager.java +136 -0
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/PushNotifications.java +339 -388
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/PushwooshNotificationServiceExtension.java +38 -0
- package/src/ios/PWBackward.h +25 -0
- package/src/ios/PWBackward.m +53 -0
- package/src/ios/PushNotification.m +409 -158
- package/src/ios/Pushwoosh.framework/Modules/module.modulemap +6 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWAppDelegate.h +20 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWGDPRManager.h +46 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInAppManager.h +174 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInbox.h +147 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInlineInAppView.h +26 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWLog.h +23 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWMessaging.h +20 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWNotificationExtensionManager.h +33 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWRichMediaManager.h +118 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWRichMediaStyle.h +122 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PushNotificationManager.h +263 -151
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/Pushwoosh.h +525 -0
- package/src/ios/Pushwoosh.framework/Versions/A/libPushwoosh.a +0 -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.framework/Modules/module.modulemap +6 -0
- package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PWIInboxStyle.h +122 -0
- package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PWIInboxUI.h +39 -0
- package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PushwooshInboxUI.h +19 -0
- package/src/ios/PushwooshInboxUI.framework/Versions/A/libPushwooshInboxUI.a +0 -0
- package/src/windows/PushSDK/Newtonsoft.Json.dll +0 -0
- package/src/windows/PushSDK/PushSDK.winmd +0 -0
- package/src/windows/PushwooshPluginProxy.js +88 -74
- package/src/wp8/PushNotification.cs +14 -0
- package/src/wp8/PushSDK/PushSDK.dll +0 -0
- package/www/PushNotification.js +171 -45
- package/Documentation/files/PushNotification-js.html +0 -157
- package/Documentation/index/Classes.html +0 -33
- package/Documentation/index/Functions.html +0 -61
- package/Documentation/index/General.html +0 -65
- package/Documentation/index.html +0 -1
- package/Documentation/javascript/main.js +0 -841
- package/Documentation/javascript/prettify.js +0 -1526
- package/Documentation/javascript/searchdata.js +0 -92
- package/Documentation/search/ClassesP.html +0 -20
- package/Documentation/search/FunctionsA.html +0 -20
- package/Documentation/search/FunctionsC.html +0 -20
- package/Documentation/search/FunctionsG.html +0 -20
- package/Documentation/search/FunctionsO.html +0 -20
- package/Documentation/search/FunctionsP.html +0 -20
- package/Documentation/search/FunctionsR.html +0 -20
- package/Documentation/search/FunctionsS.html +0 -20
- package/Documentation/search/FunctionsU.html +0 -20
- package/Documentation/search/GeneralA.html +0 -20
- package/Documentation/search/GeneralC.html +0 -20
- package/Documentation/search/GeneralF.html +0 -20
- package/Documentation/search/GeneralG.html +0 -20
- package/Documentation/search/GeneralO.html +0 -20
- package/Documentation/search/GeneralP.html +0 -20
- package/Documentation/search/GeneralR.html +0 -20
- package/Documentation/search/GeneralS.html +0 -20
- package/Documentation/search/GeneralU.html +0 -20
- package/Documentation/search/NoResults.html +0 -15
- package/Documentation/styles/main.css +0 -828
- package/VERSION.md +0 -138
- package/push.gradle +0 -21
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/NotificationFactory.java +0 -29
- 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
|
|
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
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
89
|
+
if (_callbackIds == nil) {
|
|
90
|
+
_callbackIds = [[NSMutableDictionary alloc] init];
|
|
91
|
+
}
|
|
92
|
+
return _callbackIds;
|
|
48
93
|
}
|
|
49
94
|
|
|
50
95
|
- (PushNotificationManager *)pushManager {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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,42 +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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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)];
|
|
126
201
|
}
|
|
127
202
|
|
|
128
203
|
- (void)registerDevice:(CDVInvokedUrlCommand *)command {
|
|
@@ -139,23 +214,30 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
|
|
|
139
214
|
}
|
|
140
215
|
|
|
141
216
|
- (void)unregisterDevice:(CDVInvokedUrlCommand *)command {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
+
}];
|
|
146
232
|
}
|
|
147
233
|
|
|
148
234
|
- (void)startBeaconPushes:(CDVInvokedUrlCommand *)command {
|
|
149
|
-
[
|
|
150
|
-
|
|
151
|
-
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
|
|
235
|
+
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:@{ @"error" : @"Beacon tracking is not supported" }];
|
|
152
236
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
153
237
|
}
|
|
154
238
|
|
|
155
239
|
- (void)stopBeaconPushes:(CDVInvokedUrlCommand *)command {
|
|
156
|
-
[
|
|
157
|
-
|
|
158
|
-
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:nil];
|
|
240
|
+
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:@{ @"error" : @"Beacon tracking is not supported" }];
|
|
159
241
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
160
242
|
}
|
|
161
243
|
|
|
@@ -188,102 +270,119 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
|
|
|
188
270
|
}];
|
|
189
271
|
}
|
|
190
272
|
|
|
191
|
-
- (void)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
+
}
|
|
213
311
|
}
|
|
214
312
|
|
|
215
313
|
- (void)onDidRegisterForRemoteNotificationsWithDeviceToken:(NSString *)token {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
+
}
|
|
221
320
|
}
|
|
222
321
|
|
|
223
322
|
- (void)onDidFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
[
|
|
229
|
-
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackIds[@"registerDevice"]];
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
- (void)onPushAccepted:(PushNotificationManager *)manager
|
|
233
|
-
withNotification:(NSDictionary *)pushNotification
|
|
234
|
-
onStart:(BOOL)onStart {
|
|
235
|
-
|
|
236
|
-
if (!onStart && !_deviceReady) {
|
|
237
|
-
PWLogWarn(@"PUSHWOOSH WARNING: push notification onStart is false, but onDeviceReady has not been called. Did you "
|
|
238
|
-
@"forget to call onDeviceReady?");
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
NSMutableDictionary *notification = [NSMutableDictionary new];
|
|
242
|
-
|
|
243
|
-
notification[@"onStart"] = @(onStart);
|
|
244
|
-
|
|
245
|
-
BOOL isForegound = [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
|
|
246
|
-
notification[@"foreground"] = @(isForegound);
|
|
247
|
-
|
|
248
|
-
id alert = pushNotification[@"aps"][@"alert"];
|
|
249
|
-
NSString *message = alert;
|
|
250
|
-
if ([alert isKindOfClass:[NSDictionary class]]) {
|
|
251
|
-
message = alert[@"body"];
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (message) {
|
|
255
|
-
notification[@"message"] = message;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
//pase JSON string in custom data to JSON Object
|
|
259
|
-
NSString *userdata = pushNotification[@"u"];
|
|
260
|
-
|
|
261
|
-
if (userdata) {
|
|
262
|
-
id parsedData = [NSJSONSerialization JSONObjectWithData:[userdata dataUsingEncoding:NSUTF8StringEncoding]
|
|
263
|
-
options:NSJSONReadingMutableContainers
|
|
264
|
-
error:nil];
|
|
265
|
-
|
|
266
|
-
if (parsedData) {
|
|
267
|
-
notification[@"userdata"] = parsedData;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
notification[@"ios"] = pushNotification;
|
|
272
|
-
|
|
273
|
-
PWLogDebug(@"Notification opened: %@", notification);
|
|
274
|
-
|
|
275
|
-
if (onStart) {
|
|
276
|
-
//keep the start push
|
|
277
|
-
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
|
|
278
|
-
PushNotification *pushHandler = [delegate.viewController getCommandInstance:@"PushNotification"];
|
|
279
|
-
pushHandler.startPushData = notification;
|
|
280
|
-
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"]];
|
|
281
328
|
}
|
|
329
|
+
}
|
|
282
330
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
+
}
|
|
287
386
|
}
|
|
288
387
|
|
|
289
388
|
- (void)getRemoteNotificationStatus:(CDVInvokedUrlCommand *)command {
|
|
@@ -302,10 +401,10 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
|
|
|
302
401
|
}
|
|
303
402
|
|
|
304
403
|
- (void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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];
|
|
309
408
|
}
|
|
310
409
|
|
|
311
410
|
- (void)addToApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
|
@@ -317,7 +416,7 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
|
|
|
317
416
|
}
|
|
318
417
|
|
|
319
418
|
- (void)cancelAllLocalNotifications:(CDVInvokedUrlCommand *)command {
|
|
320
|
-
[
|
|
419
|
+
[UIApplication sharedApplication].scheduledLocalNotifications = @[];
|
|
321
420
|
|
|
322
421
|
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
323
422
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
@@ -338,19 +437,177 @@ void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, cons
|
|
|
338
437
|
}
|
|
339
438
|
|
|
340
439
|
- (void)setUserId:(CDVInvokedUrlCommand *)command {
|
|
341
|
-
|
|
342
|
-
|
|
440
|
+
NSString *userId = command.arguments[0];
|
|
441
|
+
[[PWInAppManager sharedManager] setUserId:userId];
|
|
343
442
|
}
|
|
344
443
|
|
|
345
444
|
- (void) postEvent:(CDVInvokedUrlCommand *)command {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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
|
+
}
|
|
349
607
|
}
|
|
350
608
|
|
|
351
609
|
BOOL pwplugin_didRegisterUserNotificationSettings(id self, SEL _cmd, id application, id notificationSettings) {
|
|
352
|
-
|
|
353
|
-
PushNotification *pushHandler = [delegate.viewController getCommandInstance:@"PushNotification"];
|
|
610
|
+
PushNotification *pushHandler = pw_PushNotificationPlugin;
|
|
354
611
|
|
|
355
612
|
UIUserNotificationSettings *settings = notificationSettings;
|
|
356
613
|
|
|
@@ -413,10 +670,4 @@ BOOL pwplugin_didRegisterUserNotificationSettings(id self, SEL _cmd, id applicat
|
|
|
413
670
|
return YES;
|
|
414
671
|
}
|
|
415
672
|
|
|
416
|
-
- (NSObject<PushNotificationDelegate> *)getPushwooshDelegate {
|
|
417
|
-
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
|
|
418
|
-
PushNotification *pushHandler = [delegate.viewController getCommandInstance:@"PushNotification"];
|
|
419
|
-
return pushHandler;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
673
|
@end
|