pushwoosh-react-native-plugin 6.1.28 → 6.1.30
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 +1 -0
- package/index.d.ts +4 -0
- package/package.json +1 -1
- package/pushwoosh-react-native-plugin.podspec +1 -1
- package/src/android/build.gradle +1 -1
- package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshPlugin.java +2 -0
- package/src/ios/Pushwoosh.h +1 -1
- package/src/ios/PushwooshPlugin/Pushwoosh.h +1 -1
- package/src/ios/PushwooshPlugin/Pushwoosh.m +113 -43
- package/src/ios/libPushwoosh.a +0 -0
|
@@ -58,6 +58,7 @@ body:
|
|
|
58
58
|
label: Your Pushwoosh React Native Plugin version
|
|
59
59
|
description: Your React Native Plugin version which was integrated to the app. You may find it on the [releases page](https://github.com/Pushwoosh/pushwoosh-react-native-plugin/releases)
|
|
60
60
|
options:
|
|
61
|
+
- 6.1.30
|
|
61
62
|
- 6.1.28
|
|
62
63
|
- 6.1.26
|
|
63
64
|
- 6.1.25
|
package/index.d.ts
CHANGED
|
@@ -45,10 +45,14 @@ declare module 'pushwoosh-react-native-plugin' {
|
|
|
45
45
|
getShowPushnotificationAlert(callback: (willShow: boolean) => void): void;
|
|
46
46
|
getPushToken(success?: (token: string) => void): void;
|
|
47
47
|
getHwid(success: (hwid: string) => void): void;
|
|
48
|
+
getUserId(success: (userId: string) => void): void;
|
|
48
49
|
setUserId(userId: string, success?: ()=> void, fail?: (error: Error) => void): void;
|
|
49
50
|
postEvent(event: string, attributes?: Record<string, string>): void;
|
|
50
51
|
enableHuaweiPushNotifications(): void;
|
|
51
52
|
|
|
53
|
+
//email methods
|
|
54
|
+
setUserEmails(userId: string, emails: (string | string[]), success?: () => void, fail?: (error: Error) => void): void;
|
|
55
|
+
setEmails(emails: (string | string[]), success?: () => void, fail?: (error: Error) => void): void;
|
|
52
56
|
//badge methods
|
|
53
57
|
setApplicationIconBadgeNumber(badgeNumber: number): void;
|
|
54
58
|
getApplicationIconBadgeNumber(callback: (badge: number) => void): void;
|
package/package.json
CHANGED
package/src/android/build.gradle
CHANGED
|
@@ -24,6 +24,8 @@ import com.pushwoosh.RegisterForPushNotificationsResultData;
|
|
|
24
24
|
import com.pushwoosh.badge.PushwooshBadge;
|
|
25
25
|
import com.pushwoosh.exception.GetTagsException;
|
|
26
26
|
import com.pushwoosh.exception.PushwooshException;
|
|
27
|
+
import com.pushwoosh.exception.SetEmailException;
|
|
28
|
+
import com.pushwoosh.exception.SetUserException;
|
|
27
29
|
import com.pushwoosh.exception.SetUserIdException;
|
|
28
30
|
import com.pushwoosh.exception.RegisterForPushNotificationsException;
|
|
29
31
|
import com.pushwoosh.exception.UnregisterForPushNotificationException;
|
package/src/ios/Pushwoosh.h
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
#import <UserNotifications/UserNotifications.h>
|
|
16
16
|
#import <Pushwoosh/PushNotificationManager.h>
|
|
17
17
|
|
|
18
|
+
#import <objc/runtime.h>
|
|
19
|
+
|
|
18
20
|
static id objectOrNull(id object) {
|
|
19
21
|
if (object) {
|
|
20
22
|
return object;
|
|
@@ -32,6 +34,28 @@ static NSString * const kPushOpenEvent = @"PWPushOpen";
|
|
|
32
34
|
static NSString * const kPushOpenJSEvent = @"pushOpened";
|
|
33
35
|
static NSString * const kPushReceivedJSEvent = @"pushReceived";
|
|
34
36
|
|
|
37
|
+
@interface PushwooshPlugin (InnerPushwooshPlugin)
|
|
38
|
+
|
|
39
|
+
- (void) application:(UIApplication *)application pwplugin_didRegisterWithDeviceToken:(NSData *)deviceToken;
|
|
40
|
+
- (void) application:(UIApplication *)application pwplugin_didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler;
|
|
41
|
+
- (void) application:(UIApplication *)application pwplugin_didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
|
|
42
|
+
|
|
43
|
+
@end
|
|
44
|
+
|
|
45
|
+
void pushwoosh_swizzle(Class class, SEL fromChange, SEL toChange, IMP impl, const char * signature) {
|
|
46
|
+
Method method = nil;
|
|
47
|
+
method = class_getInstanceMethod(class, fromChange);
|
|
48
|
+
|
|
49
|
+
if (method) {
|
|
50
|
+
//method exists add a new method and swap with original
|
|
51
|
+
class_addMethod(class, toChange, impl, signature);
|
|
52
|
+
method_exchangeImplementations(class_getInstanceMethod(class, fromChange), class_getInstanceMethod(class, toChange));
|
|
53
|
+
} else {
|
|
54
|
+
//just add as orignal method
|
|
55
|
+
class_addMethod(class, fromChange, impl, signature);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
35
59
|
@implementation PushwooshPlugin
|
|
36
60
|
|
|
37
61
|
API_AVAILABLE(ios(10))
|
|
@@ -71,15 +95,23 @@ RCT_EXPORT_METHOD(init:(NSDictionary*)config success:(RCTResponseSenderBlock)suc
|
|
|
71
95
|
[PushNotificationManager initializeWithAppCode:appCode appName:nil];
|
|
72
96
|
[[PushNotificationManager pushManager] sendAppOpen];
|
|
73
97
|
[PushNotificationManager pushManager].delegate = self;
|
|
74
|
-
|
|
98
|
+
|
|
99
|
+
[PushwooshPlugin swizzleNotificationSettingsHandler];
|
|
75
100
|
|
|
76
101
|
// We set Pushwoosh UNUserNotificationCenter delegate unless CUSTOM is specified in the config
|
|
77
102
|
if(![notificationHandling isEqualToString:@"CUSTOM"]) {
|
|
78
103
|
if (@available(iOS 10, *)) {
|
|
104
|
+
BOOL shouldReplaceDelegate = YES;
|
|
79
105
|
|
|
80
106
|
UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
|
|
107
|
+
|
|
108
|
+
#if !TARGET_OS_OSX
|
|
109
|
+
if ([notificationCenter.delegate conformsToProtocol:@protocol(PushNotificationDelegate)]) {
|
|
110
|
+
shouldReplaceDelegate = NO;
|
|
111
|
+
}
|
|
112
|
+
#endif
|
|
81
113
|
|
|
82
|
-
if (notificationCenter.delegate != nil) {
|
|
114
|
+
if (notificationCenter.delegate != nil && shouldReplaceDelegate) {
|
|
83
115
|
_originalNotificationCenterDelegate = notificationCenter.delegate;
|
|
84
116
|
_originalNotificationCenterDelegateResponds.openSettingsForNotification =
|
|
85
117
|
(unsigned int)[_originalNotificationCenterDelegate
|
|
@@ -94,8 +126,10 @@ RCT_EXPORT_METHOD(init:(NSDictionary*)config success:(RCTResponseSenderBlock)suc
|
|
|
94
126
|
didReceiveNotificationResponse:withCompletionHandler:)];
|
|
95
127
|
}
|
|
96
128
|
|
|
97
|
-
|
|
98
|
-
|
|
129
|
+
if (shouldReplaceDelegate) {
|
|
130
|
+
__strong PushwooshPlugin<UNUserNotificationCenterDelegate> *strongSelf = (PushwooshPlugin<UNUserNotificationCenterDelegate> *)self;
|
|
131
|
+
notificationCenter.delegate = (id<UNUserNotificationCenterDelegate>)strongSelf;
|
|
132
|
+
}
|
|
99
133
|
}
|
|
100
134
|
}
|
|
101
135
|
|
|
@@ -179,27 +213,35 @@ RCT_EXPORT_METHOD(getPushToken:(RCTResponseSenderBlock)callback) {
|
|
|
179
213
|
}
|
|
180
214
|
|
|
181
215
|
RCT_EXPORT_METHOD(setEmails:(NSArray *)emails success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
|
|
216
|
+
__block NSError* gError = nil;
|
|
182
217
|
[[Pushwoosh sharedInstance] setEmails:emails completion:^(NSError * _Nullable error) {
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (error && errorCallback) {
|
|
188
|
-
errorCallback(@[ objectOrNull([error localizedDescription]) ]);
|
|
218
|
+
if (error) {
|
|
219
|
+
gError = error;
|
|
189
220
|
}
|
|
190
221
|
}];
|
|
222
|
+
if (!gError && successCallback) {
|
|
223
|
+
successCallback(@[]);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (gError && errorCallback) {
|
|
227
|
+
errorCallback(@[ objectOrNull([gError localizedDescription]) ]);
|
|
228
|
+
}
|
|
191
229
|
}
|
|
192
230
|
|
|
193
231
|
RCT_EXPORT_METHOD(setUserEmails:(NSString*)userId emails:(NSArray *)emails success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
|
|
232
|
+
__block NSError* gError = nil;
|
|
194
233
|
[[Pushwoosh sharedInstance] setUser:userId emails:emails completion:^(NSError * _Nullable error) {
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (error && errorCallback) {
|
|
200
|
-
errorCallback(@[ objectOrNull([error localizedDescription]) ]);
|
|
234
|
+
if (error) {
|
|
235
|
+
gError = error;
|
|
201
236
|
}
|
|
202
237
|
}];
|
|
238
|
+
if (!gError && successCallback) {
|
|
239
|
+
successCallback(@[]);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (gError && errorCallback) {
|
|
243
|
+
errorCallback(@[ objectOrNull([gError localizedDescription]) ]);
|
|
244
|
+
}
|
|
203
245
|
}
|
|
204
246
|
|
|
205
247
|
RCT_EXPORT_METHOD(setTags:(NSDictionary*)tags success:(RCTResponseSenderBlock)successCallback error:(RCTResponseSenderBlock)errorCallback) {
|
|
@@ -362,14 +404,54 @@ RCT_EXPORT_METHOD(performAction:(NSString*)code) {
|
|
|
362
404
|
[PWInbox performActionForMessageWithCode:code];
|
|
363
405
|
}
|
|
364
406
|
|
|
365
|
-
#pragma mark - UIApplicationDelegate Methods
|
|
366
407
|
#pragma mark -
|
|
408
|
+
#pragma mark - Swizzling
|
|
367
409
|
|
|
368
|
-
|
|
410
|
+
+ (void)swizzleNotificationSettingsHandler {
|
|
411
|
+
if ([UIApplication sharedApplication].delegate == nil) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
static Class appDelegateClass = nil;
|
|
420
|
+
|
|
421
|
+
//do not swizzle the same class twice
|
|
422
|
+
id delegate = [UIApplication sharedApplication].delegate;
|
|
423
|
+
if(appDelegateClass == [delegate class]) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
appDelegateClass = [delegate class];
|
|
428
|
+
|
|
429
|
+
pushwoosh_swizzle([delegate class], @selector(application:didRegisterForRemoteNotificationsWithDeviceToken:), @selector(application:pwplugin_didRegisterWithDeviceToken:), (IMP)pwplugin_didRegisterWithDeviceToken, "v@:::");
|
|
430
|
+
pushwoosh_swizzle([delegate class], @selector(application:didFailToRegisterForRemoteNotificationsWithError:), @selector(application:pwplugin_didFailToRegisterForRemoteNotificationsWithError:), (IMP)pwplugin_didFailToRegisterForRemoteNotificationsWithError, "v@:::");
|
|
431
|
+
pushwoosh_swizzle([delegate class], @selector(application:didReceiveRemoteNotification:fetchCompletionHandler:), @selector(application:pwplugin_didReceiveRemoteNotification:fetchCompletionHandler:), (IMP)pwplugin_didReceiveRemoteNotification, "v@::::");
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
void pwplugin_didReceiveRemoteNotification(id self, SEL _cmd, UIApplication * application, NSDictionary * userInfo, void (^completionHandler)(UIBackgroundFetchResult)) {
|
|
435
|
+
if ([self respondsToSelector:@selector(application:pwplugin_didReceiveRemoteNotification:fetchCompletionHandler:)]) {
|
|
436
|
+
[self application:application pwplugin_didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
[[Pushwoosh sharedInstance] handlePushReceived:userInfo];
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
void pwplugin_didRegisterWithDeviceToken(id self, SEL _cmd, id application, NSData *deviceToken) {
|
|
443
|
+
if ([self respondsToSelector:@selector(application: pwplugin_didRegisterWithDeviceToken:)]) {
|
|
444
|
+
[self application:application pwplugin_didRegisterWithDeviceToken:deviceToken];
|
|
445
|
+
}
|
|
446
|
+
|
|
369
447
|
[[Pushwoosh sharedInstance] handlePushRegistration:deviceToken];
|
|
370
448
|
}
|
|
371
449
|
|
|
372
|
-
|
|
450
|
+
void pwplugin_didFailToRegisterForRemoteNotificationsWithError(id self, SEL _cmd, UIApplication *application, NSError *error) {
|
|
451
|
+
if ([self respondsToSelector:@selector(application:pwplugin_didFailToRegisterForRemoteNotificationsWithError:)]) {
|
|
452
|
+
[self application:application pwplugin_didFailToRegisterForRemoteNotificationsWithError:error];
|
|
453
|
+
}
|
|
454
|
+
|
|
373
455
|
[[Pushwoosh sharedInstance] handlePushRegistrationFailure:error];
|
|
374
456
|
}
|
|
375
457
|
|
|
@@ -383,20 +465,6 @@ RCT_EXPORT_METHOD(performAction:(NSString*)code) {
|
|
|
383
465
|
API_AVAILABLE(ios(10.0)) {
|
|
384
466
|
|
|
385
467
|
if ([self isRemoteNotification:notification] && [PWMessage isPushwooshMessage:notification.request.content.userInfo]) {
|
|
386
|
-
UNMutableNotificationContent *content = notification.request.content.mutableCopy;
|
|
387
|
-
|
|
388
|
-
NSMutableDictionary *userInfo = content.userInfo.mutableCopy;
|
|
389
|
-
userInfo[@"pw_push"] = @(YES);
|
|
390
|
-
|
|
391
|
-
content.userInfo = userInfo;
|
|
392
|
-
|
|
393
|
-
//newsstand push
|
|
394
|
-
if (![self isContentAvailablePush:userInfo]) {
|
|
395
|
-
[[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushReceivedEvent withArgs:@[ objectOrNull(userInfo) ]];
|
|
396
|
-
|
|
397
|
-
[self sendJSEvent:kPushReceivedJSEvent withArgs:userInfo];
|
|
398
|
-
}
|
|
399
|
-
|
|
400
468
|
completionHandler(UNNotificationPresentationOptionNone);
|
|
401
469
|
} else if ([PushNotificationManager pushManager].showPushnotificationAlert || [notification.request.content.userInfo objectForKey:@"pw_push"] == nil) {
|
|
402
470
|
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
|
|
@@ -434,20 +502,10 @@ API_AVAILABLE(ios(10.0)) {
|
|
|
434
502
|
if (![response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier] && [[PushNotificationManager pushManager].delegate respondsToSelector:@selector(onActionIdentifierReceived:withNotification:)]) {
|
|
435
503
|
[[PushNotificationManager pushManager].delegate onActionIdentifierReceived:response.actionIdentifier withNotification:[self pushPayloadFromContent:response.notification.request.content]];
|
|
436
504
|
}
|
|
437
|
-
|
|
438
|
-
[[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(response.notification.request.content.userInfo) ]];
|
|
439
|
-
|
|
440
|
-
[self sendJSEvent:kPushOpenJSEvent withArgs:response.notification.request.content.userInfo];
|
|
441
505
|
}
|
|
442
506
|
};
|
|
443
507
|
|
|
444
508
|
if ([self isRemoteNotification:response.notification] && [PWMessage isPushwooshMessage:response.notification.request.content.userInfo]) {
|
|
445
|
-
if (![self isContentAvailablePush:response.notification.request.content.userInfo]) {
|
|
446
|
-
[[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(response.notification.request.content.userInfo) ]];
|
|
447
|
-
|
|
448
|
-
[self sendJSEvent:kPushOpenJSEvent withArgs:response.notification.request.content.userInfo];
|
|
449
|
-
}
|
|
450
|
-
|
|
451
509
|
handlePushAcceptanceBlock();
|
|
452
510
|
} else if ([response.notification.request.content.userInfo objectForKey:@"pw_push"]) {
|
|
453
511
|
handlePushAcceptanceBlock();
|
|
@@ -764,6 +822,18 @@ RCT_EXPORT_METHOD(enableHuaweiPushNotifications) {
|
|
|
764
822
|
[[PWEventDispatcher sharedDispatcher] dispatchEvent:kRegistrationErrorEvent withArgs:@[ objectOrNull([error localizedDescription]) ]];
|
|
765
823
|
}
|
|
766
824
|
|
|
825
|
+
- (void)onPushReceived:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
|
|
826
|
+
[[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushReceivedEvent withArgs:@[ objectOrNull(pushNotification) ]];
|
|
827
|
+
|
|
828
|
+
[self sendJSEvent:kPushReceivedJSEvent withArgs:pushNotification];
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
- (void)onPushAccepted:(PushNotificationManager *)manager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
|
|
832
|
+
[[PWEventDispatcher sharedDispatcher] dispatchEvent:kPushOpenEvent withArgs:@[ objectOrNull(pushNotification) ]];
|
|
833
|
+
|
|
834
|
+
[self sendJSEvent:kPushOpenJSEvent withArgs:pushNotification];
|
|
835
|
+
}
|
|
836
|
+
|
|
767
837
|
#pragma mark - RCTEventEmitter
|
|
768
838
|
|
|
769
839
|
- (void)sendJSEvent:(NSString*)event withArgs:(NSDictionary*)args {
|
package/src/ios/libPushwoosh.a
CHANGED
|
Binary file
|