pushwoosh-cordova-plugin 8.3.18 → 8.3.19

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/README.md CHANGED
@@ -14,13 +14,13 @@ Cross-Platform push notifications by Pushwoosh for Cordova / PhoneGap
14
14
  Using npm (requires cordova 7.0+):
15
15
 
16
16
  ```
17
- cordova plugin add pushwoosh-cordova-plugin@8.3.18
17
+ cordova plugin add pushwoosh-cordova-plugin@8.3.19
18
18
  ```
19
19
 
20
20
  Using git:
21
21
 
22
22
  ```
23
- cordova plugin add https://github.com/Pushwoosh/pushwoosh-phonegap-plugin.git#8.3.18
23
+ cordova plugin add https://github.com/Pushwoosh/pushwoosh-phonegap-plugin.git#8.3.19
24
24
  ```
25
25
 
26
26
  #### Phonegap
@@ -28,7 +28,7 @@ cordova plugin add https://github.com/Pushwoosh/pushwoosh-phonegap-plugin.git#8.
28
28
  Using npm (requires phonegap 7.1+):
29
29
 
30
30
  ```
31
- cordova plugin add pushwoosh-cordova-plugin@8.3.18
31
+ cordova plugin add pushwoosh-cordova-plugin@8.3.19
32
32
  ```
33
33
 
34
34
  ### Guide
package/README_PGB.md CHANGED
@@ -14,7 +14,7 @@ Cross-Platform push notifications by Pushwoosh for PhoneGap
14
14
  Using npm (requires cordova 5.0+):
15
15
 
16
16
  ```
17
- cordova plugin add pushwoosh-pgb-plugin@8.3.18
17
+ cordova plugin add pushwoosh-pgb-plugin@8.3.19
18
18
  ```
19
19
 
20
20
  ### Guide
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pushwoosh-cordova-plugin",
3
- "version": "8.3.18",
3
+ "version": "8.3.19",
4
4
  "description": "\n This plugin allows you to send and receive push notifications. Powered by Pushwoosh (www.pushwoosh.com).\n ",
5
5
  "main":"www/PushNotification.js",
6
6
  "typings":"types/index.d.ts",
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="pushwoosh-cordova-plugin" version="8.3.18">
2
+ <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="pushwoosh-cordova-plugin" version="8.3.19">
3
3
 
4
4
  <name>Pushwoosh</name>
5
5
 
@@ -15,6 +15,7 @@
15
15
  #import <PushwooshInboxUI/PushwooshInboxUI.h>
16
16
  #import <Pushwoosh/PWGDPRManager.h>
17
17
  #import <Pushwoosh/PWInAppManager.h>
18
+ #import <Pushwoosh/PushNotificationManager.h>
18
19
  #import <Pushwoosh/PWInbox.h>
19
20
  #import "PWBackward.h"
20
21
 
@@ -78,6 +79,15 @@ static PushNotification *pw_PushNotificationPlugin;
78
79
 
79
80
  @implementation PushNotification
80
81
 
82
+ API_AVAILABLE(ios(10))
83
+ __weak id<UNUserNotificationCenterDelegate> _originalNotificationCenterDelegate;
84
+ API_AVAILABLE(ios(10))
85
+ struct {
86
+ unsigned int willPresentNotification : 1;
87
+ unsigned int didReceiveNotificationResponse : 1;
88
+ unsigned int openSettingsForNotification : 1;
89
+ } _originalNotificationCenterDelegateResponds;
90
+
81
91
  #pragma clang diagnostic pop
82
92
 
83
93
  - (void)pluginInitialize {
@@ -141,7 +151,33 @@ static PushNotification *pw_PushNotificationPlugin;
141
151
  [PushNotificationManager initializeWithAppCode:appid appName:appname];
142
152
  }
143
153
 
144
- [UNUserNotificationCenter currentNotificationCenter].delegate = [PushNotificationManager pushManager].notificationCenterDelegate;
154
+ if (@available(iOS 10, *)) {
155
+ BOOL shouldReplaceDelegate = YES;
156
+ UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
157
+
158
+ if (notificationCenter.delegate != nil) {
159
+ if (shouldReplaceDelegate) {
160
+ _originalNotificationCenterDelegate = notificationCenter.delegate;
161
+ _originalNotificationCenterDelegateResponds.openSettingsForNotification =
162
+ (unsigned int)[_originalNotificationCenterDelegate
163
+ respondsToSelector:@selector(userNotificationCenter:openSettingsForNotification:)];
164
+ _originalNotificationCenterDelegateResponds.willPresentNotification =
165
+ (unsigned int)[_originalNotificationCenterDelegate
166
+ respondsToSelector:@selector(userNotificationCenter:
167
+ willPresentNotification:withCompletionHandler:)];
168
+ _originalNotificationCenterDelegateResponds.didReceiveNotificationResponse =
169
+ (unsigned int)[_originalNotificationCenterDelegate
170
+ respondsToSelector:@selector(userNotificationCenter:
171
+ didReceiveNotificationResponse:withCompletionHandler:)];
172
+ }
173
+ }
174
+
175
+ if (shouldReplaceDelegate) {
176
+ __strong PushNotification<UNUserNotificationCenterDelegate> *strongSelf = (PushNotification<UNUserNotificationCenterDelegate> *)self;
177
+ notificationCenter.delegate = (id<UNUserNotificationCenterDelegate>)strongSelf;
178
+ }
179
+ }
180
+
145
181
  [self.pushManager sendAppOpen];
146
182
 
147
183
  NSString * alertTypeString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"Pushwoosh_ALERT_TYPE"];
@@ -160,6 +196,110 @@ static PushNotification *pw_PushNotificationPlugin;
160
196
  [[NSUserDefaults standardUserDefaults] synchronize];
161
197
  }
162
198
 
199
+ #pragma mark - UNUserNotificationCenter Delegate Methods
200
+ #pragma mark -
201
+
202
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
203
+ willPresentNotification:(UNNotification *)notification
204
+ withCompletionHandler:
205
+ (void (^)(UNNotificationPresentationOptions options))completionHandler
206
+ API_AVAILABLE(ios(10.0)) {
207
+
208
+ if ([self isRemoteNotification:notification] && [PWMessage isPushwooshMessage:notification.request.content.userInfo]) {
209
+ UNMutableNotificationContent *content = notification.request.content.mutableCopy;
210
+
211
+ NSMutableDictionary *userInfo = content.userInfo.mutableCopy;
212
+ userInfo[@"pw_push"] = @(YES);
213
+
214
+ content.userInfo = userInfo;
215
+
216
+ //newsstand push
217
+ if (![self isContentAvailablePush:userInfo]) {
218
+ [[Pushwoosh sharedInstance] handlePushReceived:[self pushPayloadFromContent:content]];
219
+ }
220
+
221
+ completionHandler(UNNotificationPresentationOptionNone);
222
+ } else if ([PushNotificationManager pushManager].showPushnotificationAlert || [notification.request.content.userInfo objectForKey:@"pw_push"] == nil) {
223
+ completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
224
+ } else {
225
+ completionHandler(UNNotificationPresentationOptionNone);
226
+ }
227
+
228
+ if (_originalNotificationCenterDelegate != nil &&
229
+ _originalNotificationCenterDelegateResponds.willPresentNotification) {
230
+ [_originalNotificationCenterDelegate userNotificationCenter:center
231
+ willPresentNotification:notification
232
+ withCompletionHandler:completionHandler];
233
+ }
234
+ }
235
+
236
+ - (BOOL)isContentAvailablePush:(NSDictionary *)userInfo {
237
+ NSDictionary *apsDict = userInfo[@"aps"];
238
+ return apsDict[@"content-available"] != nil;
239
+ }
240
+
241
+ - (NSDictionary *)pushPayloadFromContent:(UNNotificationContent *)content {
242
+ return [[content.userInfo objectForKey:@"pw_push"] isKindOfClass:[NSDictionary class]] ? [content.userInfo objectForKey:@"pw_push"] : content.userInfo;
243
+ }
244
+
245
+ - (BOOL)isRemoteNotification:(UNNotification *)notification {
246
+ return [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]];
247
+ }
248
+
249
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
250
+ didReceiveNotificationResponse:(UNNotificationResponse *)response
251
+ withCompletionHandler:(void (^)(void))completionHandler
252
+ API_AVAILABLE(ios(10.0)) {
253
+ dispatch_block_t handlePushAcceptanceBlock = ^{
254
+ if (![response.actionIdentifier isEqualToString:UNNotificationDismissActionIdentifier]) {
255
+ if (![response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier] && [[PushNotificationManager pushManager].delegate respondsToSelector:@selector(onActionIdentifierReceived:withNotification:)]) {
256
+ [[PushNotificationManager pushManager].delegate onActionIdentifierReceived:response.actionIdentifier withNotification:[self pushPayloadFromContent:response.notification.request.content]];
257
+ }
258
+
259
+ [[Pushwoosh sharedInstance] handlePushReceived:[self pushPayloadFromContent:response.notification.request.content]];
260
+ }
261
+ };
262
+
263
+ if ([self isRemoteNotification:response.notification] && [PWMessage isPushwooshMessage:response.notification.request.content.userInfo]) {
264
+ if (![self isContentAvailablePush:response.notification.request.content.userInfo]) {
265
+ [[Pushwoosh sharedInstance] handlePushReceived:[self pushPayloadFromContent:response.notification.request.content]];
266
+ }
267
+
268
+ handlePushAcceptanceBlock();
269
+ } else if ([response.notification.request.content.userInfo objectForKey:@"pw_push"]) {
270
+ handlePushAcceptanceBlock();
271
+ }
272
+
273
+ if (_originalNotificationCenterDelegate != nil &&
274
+ _originalNotificationCenterDelegateResponds.didReceiveNotificationResponse) {
275
+ [_originalNotificationCenterDelegate userNotificationCenter:center
276
+ didReceiveNotificationResponse:response
277
+ withCompletionHandler:completionHandler];
278
+ } else {
279
+ completionHandler();
280
+ }
281
+ }
282
+
283
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
284
+ openSettingsForNotification:(nullable UNNotification *)notification
285
+ API_AVAILABLE(ios(10.0)) {
286
+ if ([[PushNotificationManager pushManager].delegate respondsToSelector:@selector(pushManager:openSettingsForNotification:)]) {
287
+ #pragma clang diagnostic push
288
+ #pragma clang diagnostic ignored "-Wpartial-availability"
289
+ [[PushNotificationManager pushManager].delegate pushManager:[PushNotificationManager pushManager] openSettingsForNotification:notification];
290
+ #pragma clang diagnostic pop
291
+ }
292
+
293
+ if (_originalNotificationCenterDelegate != nil &&
294
+ _originalNotificationCenterDelegateResponds.openSettingsForNotification) {
295
+ #pragma clang diagnostic push
296
+ #pragma clang diagnostic ignored "-Wunguarded-availability-new"
297
+ [_originalNotificationCenterDelegate userNotificationCenter:center
298
+ openSettingsForNotification:notification];
299
+ #pragma clang diagnostic pop
300
+ }
301
+ }
302
+
163
303
  // Authorization options in addition to UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay. Should be called before registering for pushes
164
304
  - (void)additionalAuthorizationOptions:(CDVInvokedUrlCommand *)command {
165
305
  NSDictionary *options = [command.arguments firstObject];