@onekeyfe/react-native-jpush 6.7.0-alpha.449 → 6.7.0-alpha.466
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/android/fcm/src/test/java/com/onekey/jpush/fcm/FcmAdapterTest.java +212 -0
- package/android/src/main/cpp/cpp-adapter.cpp +41 -1
- package/android/src/main/java/cn/jiguang/core/JCoreCrypto.java +6 -9
- package/android/src/main/java/cn/jiguang/core/JCoreStorage.java +14 -2
- package/android/src/main/java/cn/jiguang/core/JCoreTcpEngine.java +476 -348
- package/android/src/main/java/cn/jiguang/core/JCoreWireCodec.java +1 -0
- package/android/src/main/java/cn/jiguang/plugins/core/JCoreModule.java +13 -2
- package/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +38 -2
- package/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java +46 -15
- package/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java +0 -3
- package/android/src/main/java/cn/jpush/android/api/JPushInterface.java +0 -1
- package/android/src/main/java/cn/jpush/android/local/ActionHelper.java +223 -272
- package/android/src/main/java/cn/jpush/android/service/JNotifyActivity.java +1 -1
- package/android/src/main/java/com/margelo/nitro/reactnativejpush/ReactNativeJpush.kt +51 -16
- package/android/src/test/java/com/margelo/nitro/reactnativejpush/ReactNativeJpushProtocolTest.java +76 -32
- package/ios/bridge/RCTJPushModule.m +215 -150
- package/ios/jcore/JCOREConfiguration.h +5 -0
- package/ios/jcore/JCOREConfiguration.m +44 -4
- package/ios/jcore/JCORECrypto.m +10 -12
- package/ios/jcore/JCORETcpSession.m +197 -45
- package/ios/jcore/JCOREWireProtocol.m +20 -7
- package/ios/jpush/JPUSHNotificationManager.m +7 -1
- package/ios/jpush/JPUSHService.m +7 -9
- package/package.json +1 -1
|
@@ -75,6 +75,7 @@ static RCTJPushModule *sNotificationObserverHelper = nil;
|
|
|
75
75
|
|
|
76
76
|
@interface RCTJPushModule () <RCTBridgeModule, JPUSHRegisterDelegate, JPUSHInAppMessageDelegate> {
|
|
77
77
|
BOOL _hasListeners;
|
|
78
|
+
BOOL _invalidated;
|
|
78
79
|
}
|
|
79
80
|
@property (nonatomic, weak, nullable) RCTBridge *bridge;
|
|
80
81
|
@end
|
|
@@ -86,7 +87,7 @@ static RCTJPushModule *sNotificationObserverHelper = nil;
|
|
|
86
87
|
RCT_EXPORT_MODULE(JPushModule);
|
|
87
88
|
|
|
88
89
|
+ (void)registerActiveModule:(RCTJPushModule *)module {
|
|
89
|
-
if (module == nil) {
|
|
90
|
+
if (module == nil || module->_invalidated) {
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
93
|
@synchronized (RCTJPushModule.class) {
|
|
@@ -126,9 +127,43 @@ RCT_EXPORT_MODULE(JPushModule);
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
+ (BOOL)isContentEvent:(NSString *)name {
|
|
131
|
+
return [@[NOTIFICATION_EVENT, LOCAL_NOTIFICATION_EVENT, CUSTOM_MESSAGE_EVENT,
|
|
132
|
+
INAPP_MESSAGE_EVENT, @"NotifyButtonClickEvent"] containsObject:name];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
+ (BOOL)canDeliverEvent:(NSString *)name generation:(NSUInteger)generation {
|
|
136
|
+
return ![self isContentEvent:name] || [[JCOREConfiguration shared] allowsPolicyGeneration:generation];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
+ (void)policyDidChange:(NSNotification *)notification {
|
|
140
|
+
(void)notification;
|
|
141
|
+
@synchronized (RCTJPushModule.class) {
|
|
142
|
+
NSUInteger generation = [JCOREConfiguration shared].policyGeneration;
|
|
143
|
+
BOOL allowed = [JCOREConfiguration shared].policyAllowsPush;
|
|
144
|
+
NSIndexSet *events = [sPendingEvents indexesOfObjectsPassingTest:^BOOL(NSDictionary *item, NSUInteger index, BOOL *stop) {
|
|
145
|
+
return [self isContentEvent:item[@"name"]] && (!allowed || [item[@"generation"] unsignedIntegerValue] != generation);
|
|
146
|
+
}];
|
|
147
|
+
[sPendingEvents removeObjectsAtIndexes:events];
|
|
148
|
+
NSIndexSet *nitro = [sPendingNitroEvents indexesOfObjectsPassingTest:^BOOL(NSDictionary *item, NSUInteger index, BOOL *stop) {
|
|
149
|
+
return [self isContentEvent:item[@"name"]] && (!allowed || [item[@"generation"] unsignedIntegerValue] != generation);
|
|
150
|
+
}];
|
|
151
|
+
[sPendingNitroEvents removeObjectsAtIndexes:nitro];
|
|
152
|
+
for (NSMutableArray<NSDictionary *> *queue in @[[RCTJPushEventQueue sharedInstance]._notificationQueue ?: [NSMutableArray array],
|
|
153
|
+
[RCTJPushEventQueue sharedInstance]._localNotificationQueue ?: [NSMutableArray array]]) {
|
|
154
|
+
NSIndexSet *stale = [queue indexesOfObjectsPassingTest:^BOOL(NSDictionary *item, NSUInteger index, BOOL *stop) {
|
|
155
|
+
return !allowed || item[@"_j_InternalPolicyGeneration"] == nil ||
|
|
156
|
+
[item[@"_j_InternalPolicyGeneration"] unsignedIntegerValue] != generation;
|
|
157
|
+
}];
|
|
158
|
+
[queue removeObjectsAtIndexes:stale];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
129
163
|
+ (void)ensureSharedNativeObservers {
|
|
130
164
|
@synchronized (RCTJPushModule.class) {
|
|
131
165
|
if (sNotificationObserverHelper == nil) {
|
|
166
|
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(policyDidChange:) name:JCOREPolicyDidChangeNotification object:nil];
|
|
132
167
|
sNotificationObserverHelper = [[RCTJPushModule alloc] initAsSharedObserver];
|
|
133
168
|
}
|
|
134
169
|
}
|
|
@@ -235,6 +270,7 @@ RCT_EXPORT_METHOD(removeListeners:(double)count) {
|
|
|
235
270
|
}
|
|
236
271
|
|
|
237
272
|
- (BOOL)canEmitEventsNow {
|
|
273
|
+
if (_invalidated) { return NO; }
|
|
238
274
|
if (self.bridge != nil) {
|
|
239
275
|
return YES;
|
|
240
276
|
}
|
|
@@ -251,7 +287,7 @@ RCT_EXPORT_METHOD(removeListeners:(double)count) {
|
|
|
251
287
|
}
|
|
252
288
|
|
|
253
289
|
- (BOOL)emitToDeviceEventEmitter:(NSString *)eventName payload:(NSDictionary *)payload {
|
|
254
|
-
if (eventName.length == 0) {
|
|
290
|
+
if (_invalidated || eventName.length == 0) {
|
|
255
291
|
return NO;
|
|
256
292
|
}
|
|
257
293
|
NSDictionary *safePayload = payload ?: @{};
|
|
@@ -279,72 +315,62 @@ RCT_EXPORT_METHOD(removeListeners:(double)count) {
|
|
|
279
315
|
}
|
|
280
316
|
|
|
281
317
|
+ (void)emitEventWithName:(NSString *)eventName payload:(NSDictionary *)payload {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
318
|
+
[self emitEventWithName:eventName payload:payload generation:[JCOREConfiguration shared].policyGeneration];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
+ (void)emitEventWithName:(NSString *)eventName payload:(NSDictionary *)payload generation:(NSUInteger)generation {
|
|
322
|
+
if (eventName.length == 0 || ![self canDeliverEvent:eventName generation:generation]) { return; }
|
|
285
323
|
[self ensureSharedNativeObservers];
|
|
286
324
|
NSDictionary *safePayload = payload ?: @{};
|
|
287
|
-
NSArray<RCTJPushModule *> *modules = [self allActiveModules];
|
|
288
325
|
BOOL emittedToLegacy = NO;
|
|
289
|
-
for (RCTJPushModule *module in
|
|
290
|
-
if ([module emitToDeviceEventEmitter:eventName payload:safePayload]) {
|
|
291
|
-
emittedToLegacy = YES;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (!emittedToLegacy) {
|
|
326
|
+
for (RCTJPushModule *module in [self allActiveModules]) {
|
|
295
327
|
@synchronized (RCTJPushModule.class) {
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
if (sPendingEvents.count >= 64) {
|
|
300
|
-
[sPendingEvents removeObjectAtIndex:0];
|
|
301
|
-
}
|
|
302
|
-
[sPendingEvents addObject:@{
|
|
303
|
-
@"name": eventName,
|
|
304
|
-
@"payload": safePayload,
|
|
305
|
-
}];
|
|
328
|
+
if (![self canDeliverEvent:eventName generation:generation]) { return; }
|
|
329
|
+
if ([module emitToDeviceEventEmitter:eventName payload:safePayload]) { emittedToLegacy = YES; }
|
|
306
330
|
}
|
|
307
331
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
NSArray<RCTJPushNitroEventListener> *nitroListeners = nil;
|
|
332
|
+
NSString *json = [self dictionaryToJsonString:safePayload];
|
|
333
|
+
NSDictionary<NSNumber *, RCTJPushNitroEventListener> *listeners = nil;
|
|
311
334
|
@synchronized (RCTJPushModule.class) {
|
|
312
|
-
if (
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
[sPendingNitroEvents
|
|
322
|
-
|
|
323
|
-
@"json": payloadJson,
|
|
324
|
-
}];
|
|
335
|
+
if (![self canDeliverEvent:eventName generation:generation]) { return; }
|
|
336
|
+
if (!emittedToLegacy) {
|
|
337
|
+
if (sPendingEvents == nil) { sPendingEvents = [NSMutableArray array]; }
|
|
338
|
+
if (sPendingEvents.count >= 64) { [sPendingEvents removeObjectAtIndex:0]; }
|
|
339
|
+
[sPendingEvents addObject:@{@"name": eventName, @"payload": safePayload, @"generation": @(generation)}];
|
|
340
|
+
}
|
|
341
|
+
listeners = [sNitroListeners copy];
|
|
342
|
+
if (listeners.count == 0) {
|
|
343
|
+
if (sPendingNitroEvents == nil) { sPendingNitroEvents = [NSMutableArray array]; }
|
|
344
|
+
if (sPendingNitroEvents.count >= 64) { [sPendingNitroEvents removeObjectAtIndex:0]; }
|
|
345
|
+
[sPendingNitroEvents addObject:@{@"name": eventName, @"json": json, @"generation": @(generation)}];
|
|
325
346
|
}
|
|
326
347
|
}
|
|
327
|
-
for (
|
|
328
|
-
|
|
348
|
+
for (NSNumber *listenerId in listeners) {
|
|
349
|
+
@synchronized (RCTJPushModule.class) {
|
|
350
|
+
if ([self canDeliverEvent:eventName generation:generation] && sNitroListeners[listenerId] == listeners[listenerId]) {
|
|
351
|
+
listeners[listenerId](eventName, json);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
329
354
|
}
|
|
330
355
|
}
|
|
331
356
|
|
|
332
357
|
+ (void)flushPendingNitroEvents {
|
|
333
|
-
|
|
334
|
-
NSArray<NSDictionary *> *
|
|
358
|
+
NSDictionary<NSNumber *, RCTJPushNitroEventListener> *listeners = nil;
|
|
359
|
+
NSArray<NSDictionary *> *snapshot = nil;
|
|
335
360
|
@synchronized (RCTJPushModule.class) {
|
|
336
|
-
if (sNitroListeners.count > 0
|
|
337
|
-
|
|
338
|
-
|
|
361
|
+
if (sNitroListeners.count > 0) {
|
|
362
|
+
listeners = [sNitroListeners copy];
|
|
363
|
+
snapshot = [sPendingNitroEvents copy];
|
|
339
364
|
[sPendingNitroEvents removeAllObjects];
|
|
340
365
|
}
|
|
341
366
|
}
|
|
342
|
-
for (NSDictionary *item in
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
367
|
+
for (NSDictionary *item in snapshot) {
|
|
368
|
+
for (NSNumber *listenerId in listeners) {
|
|
369
|
+
@synchronized (RCTJPushModule.class) {
|
|
370
|
+
if ([self canDeliverEvent:item[@"name"] generation:[item[@"generation"] unsignedIntegerValue]] &&
|
|
371
|
+
sNitroListeners[listenerId] == listeners[listenerId]) {
|
|
372
|
+
listeners[listenerId](item[@"name"], item[@"json"] ?: @"{}");
|
|
373
|
+
}
|
|
348
374
|
}
|
|
349
375
|
}
|
|
350
376
|
}
|
|
@@ -353,32 +379,22 @@ RCT_EXPORT_METHOD(removeListeners:(double)count) {
|
|
|
353
379
|
+ (void)flushPendingBridgeEvents {
|
|
354
380
|
[self ensureSharedNativeObservers];
|
|
355
381
|
[self flushPendingNitroEvents];
|
|
356
|
-
|
|
357
382
|
NSArray<RCTJPushModule *> *modules = [self allActiveModules];
|
|
358
|
-
BOOL
|
|
359
|
-
for (RCTJPushModule *
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
if (!hasReadyLegacy) {
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
NSArray<NSDictionary *> *pendingSnapshot = nil;
|
|
383
|
+
BOOL ready = NO;
|
|
384
|
+
for (RCTJPushModule *module in modules) { if ([module canEmitEventsNow]) { ready = YES; break; } }
|
|
385
|
+
if (!ready) { return; }
|
|
386
|
+
NSArray<NSDictionary *> *snapshot = nil;
|
|
370
387
|
@synchronized (RCTJPushModule.class) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
[sPendingEvents removeAllObjects];
|
|
374
|
-
}
|
|
388
|
+
snapshot = [sPendingEvents copy];
|
|
389
|
+
[sPendingEvents removeAllObjects];
|
|
375
390
|
}
|
|
376
|
-
for (NSDictionary *item in
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
391
|
+
for (NSDictionary *item in snapshot) {
|
|
392
|
+
for (RCTJPushModule *module in modules) {
|
|
393
|
+
@synchronized (RCTJPushModule.class) {
|
|
394
|
+
if ([self canDeliverEvent:item[@"name"] generation:[item[@"generation"] unsignedIntegerValue]] &&
|
|
395
|
+
[[self allActiveModules] containsObject:module]) {
|
|
396
|
+
[module emitToDeviceEventEmitter:item[@"name"] payload:item[@"payload"] ?: @{}];
|
|
397
|
+
}
|
|
382
398
|
}
|
|
383
399
|
}
|
|
384
400
|
}
|
|
@@ -388,24 +404,28 @@ RCT_EXPORT_METHOD(removeListeners:(double)count) {
|
|
|
388
404
|
[self ensureSharedNativeObservers];
|
|
389
405
|
[self flushPendingBridgeEvents];
|
|
390
406
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
407
|
+
NSUInteger generation = [JCOREConfiguration shared].policyGeneration;
|
|
408
|
+
if (![JCOREConfiguration shared].policyAllowsPush) { [self policyDidChange:nil]; return; }
|
|
409
|
+
@synchronized (RCTJPushModule.class) {
|
|
410
|
+
RCTJPushModule *converter = sNotificationObserverHelper ?: [self allActiveModules].firstObject;
|
|
411
|
+
NSMutableArray *notificationList = [RCTJPushEventQueue sharedInstance]._notificationQueue;
|
|
412
|
+
if (notificationList.count > 0) {
|
|
413
|
+
NSArray *queuedApns = [notificationList copy];
|
|
414
|
+
[notificationList removeAllObjects];
|
|
415
|
+
for (id obj in queuedApns) {
|
|
416
|
+
if ([[JCOREConfiguration shared] allowsPolicyGeneration:generation] && [obj isKindOfClass:[NSDictionary class]]) {
|
|
417
|
+
[converter sendApnsNotificationEventByDictionary:(NSDictionary *)obj];
|
|
418
|
+
}
|
|
399
419
|
}
|
|
400
420
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
421
|
+
NSMutableArray *localNotificationList = [RCTJPushEventQueue sharedInstance]._localNotificationQueue;
|
|
422
|
+
if (localNotificationList.count > 0) {
|
|
423
|
+
NSArray *queuedLocal = [localNotificationList copy];
|
|
424
|
+
[localNotificationList removeAllObjects];
|
|
425
|
+
for (id obj in queuedLocal) {
|
|
426
|
+
if ([[JCOREConfiguration shared] allowsPolicyGeneration:generation] && [obj isKindOfClass:[NSDictionary class]]) {
|
|
427
|
+
[converter sendLocalNotificationEventByDictionary:(NSDictionary *)obj];
|
|
428
|
+
}
|
|
409
429
|
}
|
|
410
430
|
}
|
|
411
431
|
}
|
|
@@ -486,6 +506,17 @@ RCT_EXPORT_METHOD(removeListeners:(double)count) {
|
|
|
486
506
|
return self;
|
|
487
507
|
}
|
|
488
508
|
|
|
509
|
+
- (void)invalidate {
|
|
510
|
+
@synchronized (RCTJPushModule.class) {
|
|
511
|
+
_invalidated = YES;
|
|
512
|
+
_hasListeners = NO;
|
|
513
|
+
_bridge = nil;
|
|
514
|
+
[sActiveModules removeObject:self];
|
|
515
|
+
if (sSharedJPushModule == self) { sSharedJPushModule = sActiveModules.allObjects.lastObject; }
|
|
516
|
+
}
|
|
517
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
518
|
+
}
|
|
519
|
+
|
|
489
520
|
- (void)dealloc {
|
|
490
521
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
491
522
|
}
|
|
@@ -730,21 +761,24 @@ RCT_EXPORT_METHOD(setBackgroundEnable:(BOOL)enable) {
|
|
|
730
761
|
willPresentNotification:(UNNotification *)notification
|
|
731
762
|
withCompletionHandler:(void (^)(NSInteger))completionHandler {
|
|
732
763
|
(void)center;
|
|
764
|
+
NSUInteger generation = [JCOREConfiguration shared].policyGeneration;
|
|
733
765
|
NSDictionary *userInfo = notification.request.content.userInfo ?: @{};
|
|
766
|
+
NSMutableDictionary *notificationInfo = [NSMutableDictionary dictionaryWithDictionary:userInfo];
|
|
767
|
+
notificationInfo[@"_j_InternalPolicyGeneration"] = @(generation);
|
|
734
768
|
if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
|
|
735
769
|
[JPUSHService handleRemoteNotification:userInfo];
|
|
736
770
|
[[NSNotificationCenter defaultCenter] postNotificationName:J_APNS_NOTIFICATION_ARRIVED_EVENT
|
|
737
771
|
object:userInfo
|
|
738
|
-
userInfo:
|
|
772
|
+
userInfo:notificationInfo];
|
|
739
773
|
} else {
|
|
740
774
|
[[NSNotificationCenter defaultCenter] postNotificationName:J_LOCAL_NOTIFICATION_ARRIVED_EVENT
|
|
741
775
|
object:userInfo
|
|
742
|
-
userInfo:
|
|
776
|
+
userInfo:notificationInfo];
|
|
743
777
|
}
|
|
744
778
|
if (completionHandler != nil) {
|
|
745
|
-
completionHandler(
|
|
746
|
-
|
|
747
|
-
|
|
779
|
+
completionHandler([[JCOREConfiguration shared] allowsPolicyGeneration:generation]
|
|
780
|
+
? UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert
|
|
781
|
+
: UNNotificationPresentationOptionNone);
|
|
748
782
|
}
|
|
749
783
|
}
|
|
750
784
|
|
|
@@ -752,16 +786,19 @@ RCT_EXPORT_METHOD(setBackgroundEnable:(BOOL)enable) {
|
|
|
752
786
|
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|
753
787
|
withCompletionHandler:(void (^)(void))completionHandler {
|
|
754
788
|
(void)center;
|
|
789
|
+
NSUInteger generation = [JCOREConfiguration shared].policyGeneration;
|
|
755
790
|
NSDictionary *userInfo = response.notification.request.content.userInfo ?: @{};
|
|
791
|
+
NSMutableDictionary *notificationInfo = [NSMutableDictionary dictionaryWithDictionary:userInfo];
|
|
792
|
+
notificationInfo[@"_j_InternalPolicyGeneration"] = @(generation);
|
|
756
793
|
if ([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
|
|
757
794
|
[JPUSHService handleRemoteNotification:userInfo];
|
|
758
795
|
[[NSNotificationCenter defaultCenter] postNotificationName:J_APNS_NOTIFICATION_OPENED_EVENT
|
|
759
796
|
object:userInfo
|
|
760
|
-
userInfo:
|
|
797
|
+
userInfo:notificationInfo];
|
|
761
798
|
} else {
|
|
762
799
|
[[NSNotificationCenter defaultCenter] postNotificationName:J_LOCAL_NOTIFICATION_OPENED_EVENT
|
|
763
800
|
object:userInfo
|
|
764
|
-
userInfo:
|
|
801
|
+
userInfo:notificationInfo];
|
|
765
802
|
}
|
|
766
803
|
if (completionHandler != nil) {
|
|
767
804
|
completionHandler();
|
|
@@ -926,81 +963,107 @@ RCT_EXPORT_METHOD(setGeofeneceMaxCount:(NSDictionary *)params) {
|
|
|
926
963
|
}
|
|
927
964
|
|
|
928
965
|
- (void)sendApnsNotificationEvent:(NSNotification *)data {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
if (
|
|
934
|
-
|
|
935
|
-
|
|
966
|
+
NSUInteger generation = [data.userInfo[@"_j_InternalPolicyGeneration"] respondsToSelector:@selector(unsignedIntegerValue)]
|
|
967
|
+
? [data.userInfo[@"_j_InternalPolicyGeneration"] unsignedIntegerValue] : [JCOREConfiguration shared].policyGeneration;
|
|
968
|
+
@synchronized (RCTJPushModule.class) {
|
|
969
|
+
if (![[JCOREConfiguration shared] allowsPolicyGeneration:generation]) { return; }
|
|
970
|
+
if (![RCTJPushModule hasReadyEventConsumer]) {
|
|
971
|
+
NSDictionary *objectData = [data.object isKindOfClass:[NSDictionary class]]
|
|
972
|
+
? data.object
|
|
973
|
+
: ([data.userInfo isKindOfClass:[NSDictionary class]] ? data.userInfo : nil);
|
|
974
|
+
if (objectData != nil) {
|
|
975
|
+
if ([RCTJPushEventQueue sharedInstance]._notificationQueue == nil) {
|
|
976
|
+
[RCTJPushEventQueue sharedInstance]._notificationQueue = [NSMutableArray array];
|
|
977
|
+
}
|
|
978
|
+
NSMutableDictionary *queuedItem = [NSMutableDictionary dictionaryWithDictionary:objectData];
|
|
979
|
+
queuedItem[@"_j_InternalPolicyGeneration"] = @(generation);
|
|
980
|
+
queuedItem[@"_j_InternalNotificationName"] = data.name ?: J_APNS_NOTIFICATION_OPENED_EVENT;
|
|
981
|
+
[[RCTJPushEventQueue sharedInstance]._notificationQueue addObject:[queuedItem copy]];
|
|
936
982
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
NSDictionary *responseData = [self convertApnsMessage:data];
|
|
986
|
+
[JCOREConfiguration logInfo:[NSString stringWithFormat:@"onNotifyMessage type=%@ notificationType=remote msgId=%@",
|
|
987
|
+
responseData[NOTIFICATION_EVENT_TYPE] ?: @"",
|
|
988
|
+
responseData[MESSAGE_ID] ?: @""]];
|
|
989
|
+
[RCTJPushModule emitEventWithName:NOTIFICATION_EVENT payload:responseData generation:generation];
|
|
990
|
+
if ([RCTJPushEventQueue sharedInstance]._notificationQueue.count > 0) {
|
|
991
|
+
[[RCTJPushEventQueue sharedInstance]._notificationQueue removeAllObjects];
|
|
940
992
|
}
|
|
941
|
-
return;
|
|
942
|
-
}
|
|
943
|
-
NSDictionary *responseData = [self convertApnsMessage:data];
|
|
944
|
-
[JCOREConfiguration logInfo:[NSString stringWithFormat:@"onNotifyMessage type=%@ notificationType=remote msgId=%@",
|
|
945
|
-
responseData[NOTIFICATION_EVENT_TYPE] ?: @"",
|
|
946
|
-
responseData[MESSAGE_ID] ?: @""]];
|
|
947
|
-
[RCTJPushModule emitEventWithName:NOTIFICATION_EVENT payload:responseData];
|
|
948
|
-
if ([RCTJPushEventQueue sharedInstance]._notificationQueue.count > 0) {
|
|
949
|
-
[[RCTJPushEventQueue sharedInstance]._notificationQueue removeAllObjects];
|
|
950
993
|
}
|
|
951
994
|
}
|
|
952
995
|
|
|
953
996
|
- (void)sendApnsNotificationEventByDictionary:(NSDictionary *)data {
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
997
|
+
NSUInteger generation = [data[@"_j_InternalPolicyGeneration"] respondsToSelector:@selector(unsignedIntegerValue)]
|
|
998
|
+
? [data[@"_j_InternalPolicyGeneration"] unsignedIntegerValue] : [JCOREConfiguration shared].policyGeneration;
|
|
999
|
+
@synchronized (RCTJPushModule.class) {
|
|
1000
|
+
if (![[JCOREConfiguration shared] allowsPolicyGeneration:generation]) { return; }
|
|
1001
|
+
NSDictionary *responseData = [self convertApnsMessage:data];
|
|
1002
|
+
[JCOREConfiguration logInfo:[NSString stringWithFormat:@"onNotifyMessage type=%@ notificationType=remote msgId=%@",
|
|
1003
|
+
responseData[NOTIFICATION_EVENT_TYPE] ?: @"",
|
|
1004
|
+
responseData[MESSAGE_ID] ?: @""]];
|
|
1005
|
+
[RCTJPushModule emitEventWithName:NOTIFICATION_EVENT payload:responseData generation:generation];
|
|
1006
|
+
if ([RCTJPushEventQueue sharedInstance]._notificationQueue.count > 0) {
|
|
1007
|
+
[[RCTJPushEventQueue sharedInstance]._notificationQueue removeAllObjects];
|
|
1008
|
+
}
|
|
961
1009
|
}
|
|
962
1010
|
}
|
|
963
1011
|
|
|
964
1012
|
- (void)sendLocalNotificationEventByDictionary:(NSDictionary *)data {
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
1013
|
+
NSUInteger generation = [data[@"_j_InternalPolicyGeneration"] respondsToSelector:@selector(unsignedIntegerValue)]
|
|
1014
|
+
? [data[@"_j_InternalPolicyGeneration"] unsignedIntegerValue] : [JCOREConfiguration shared].policyGeneration;
|
|
1015
|
+
@synchronized (RCTJPushModule.class) {
|
|
1016
|
+
if (![[JCOREConfiguration shared] allowsPolicyGeneration:generation]) { return; }
|
|
1017
|
+
NSDictionary *responseData = [self convertLocalMessage:data];
|
|
1018
|
+
[JCOREConfiguration logInfo:[NSString stringWithFormat:@"onLocalNotification type=%@ notificationType=local msgId=%@",
|
|
1019
|
+
responseData[NOTIFICATION_EVENT_TYPE] ?: @"",
|
|
1020
|
+
responseData[MESSAGE_ID] ?: @""]];
|
|
1021
|
+
[RCTJPushModule emitEventWithName:LOCAL_NOTIFICATION_EVENT payload:responseData generation:generation];
|
|
1022
|
+
if ([RCTJPushEventQueue sharedInstance]._localNotificationQueue.count > 0) {
|
|
1023
|
+
[[RCTJPushEventQueue sharedInstance]._localNotificationQueue removeAllObjects];
|
|
1024
|
+
}
|
|
972
1025
|
}
|
|
973
1026
|
}
|
|
974
1027
|
|
|
975
1028
|
- (void)sendCustomNotificationEvent:(NSNotification *)data {
|
|
1029
|
+
NSDictionary *objectData = [data.object isKindOfClass:[NSDictionary class]] ? data.object : nil;
|
|
1030
|
+
id originGeneration = data.userInfo[@"_j_InternalPolicyGeneration"] ?: objectData[@"_j_InternalPolicyGeneration"];
|
|
1031
|
+
NSUInteger generation = [originGeneration respondsToSelector:@selector(unsignedIntegerValue)]
|
|
1032
|
+
? [originGeneration unsignedIntegerValue] : [JCOREConfiguration shared].policyGeneration;
|
|
976
1033
|
NSDictionary *responseData = [self convertCustomMessage:data];
|
|
977
1034
|
[JCOREConfiguration logInfo:[NSString stringWithFormat:@"onMessage type=customMessage msgId=%@",
|
|
978
1035
|
responseData[MESSAGE_ID] ?: @""]];
|
|
979
|
-
[RCTJPushModule emitEventWithName:CUSTOM_MESSAGE_EVENT payload:responseData];
|
|
1036
|
+
[RCTJPushModule emitEventWithName:CUSTOM_MESSAGE_EVENT payload:responseData generation:generation];
|
|
980
1037
|
}
|
|
981
1038
|
|
|
982
1039
|
- (void)sendLocalNotificationEvent:(NSNotification *)data {
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
if (
|
|
988
|
-
|
|
989
|
-
|
|
1040
|
+
NSUInteger generation = [data.userInfo[@"_j_InternalPolicyGeneration"] respondsToSelector:@selector(unsignedIntegerValue)]
|
|
1041
|
+
? [data.userInfo[@"_j_InternalPolicyGeneration"] unsignedIntegerValue] : [JCOREConfiguration shared].policyGeneration;
|
|
1042
|
+
@synchronized (RCTJPushModule.class) {
|
|
1043
|
+
if (![[JCOREConfiguration shared] allowsPolicyGeneration:generation]) { return; }
|
|
1044
|
+
if (![RCTJPushModule hasReadyEventConsumer]) {
|
|
1045
|
+
NSDictionary *objectData = [data.object isKindOfClass:[NSDictionary class]]
|
|
1046
|
+
? data.object
|
|
1047
|
+
: ([data.userInfo isKindOfClass:[NSDictionary class]] ? data.userInfo : nil);
|
|
1048
|
+
if (objectData != nil) {
|
|
1049
|
+
if ([RCTJPushEventQueue sharedInstance]._localNotificationQueue == nil) {
|
|
1050
|
+
[RCTJPushEventQueue sharedInstance]._localNotificationQueue = [NSMutableArray array];
|
|
1051
|
+
}
|
|
1052
|
+
NSMutableDictionary *queuedItem = [NSMutableDictionary dictionaryWithDictionary:objectData];
|
|
1053
|
+
queuedItem[@"_j_InternalPolicyGeneration"] = @(generation);
|
|
1054
|
+
queuedItem[@"_j_InternalNotificationName"] = data.name ?: J_LOCAL_NOTIFICATION_OPENED_EVENT;
|
|
1055
|
+
[[RCTJPushEventQueue sharedInstance]._localNotificationQueue addObject:[queuedItem copy]];
|
|
990
1056
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
NSDictionary *responseData = [self convertLocalMessage:data];
|
|
1060
|
+
[JCOREConfiguration logInfo:[NSString stringWithFormat:@"onLocalNotification type=%@ notificationType=local msgId=%@",
|
|
1061
|
+
responseData[NOTIFICATION_EVENT_TYPE] ?: @"",
|
|
1062
|
+
responseData[MESSAGE_ID] ?: @""]];
|
|
1063
|
+
[RCTJPushModule emitEventWithName:LOCAL_NOTIFICATION_EVENT payload:responseData generation:generation];
|
|
1064
|
+
if ([RCTJPushEventQueue sharedInstance]._localNotificationQueue.count > 0) {
|
|
1065
|
+
[[RCTJPushEventQueue sharedInstance]._localNotificationQueue removeAllObjects];
|
|
994
1066
|
}
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
NSDictionary *responseData = [self convertLocalMessage:data];
|
|
998
|
-
[JCOREConfiguration logInfo:[NSString stringWithFormat:@"onLocalNotification type=%@ notificationType=local msgId=%@",
|
|
999
|
-
responseData[NOTIFICATION_EVENT_TYPE] ?: @"",
|
|
1000
|
-
responseData[MESSAGE_ID] ?: @""]];
|
|
1001
|
-
[RCTJPushModule emitEventWithName:LOCAL_NOTIFICATION_EVENT payload:responseData];
|
|
1002
|
-
if ([RCTJPushEventQueue sharedInstance]._localNotificationQueue.count > 0) {
|
|
1003
|
-
[[RCTJPushEventQueue sharedInstance]._localNotificationQueue removeAllObjects];
|
|
1004
1067
|
}
|
|
1005
1068
|
}
|
|
1006
1069
|
|
|
@@ -1058,6 +1121,7 @@ RCT_EXPORT_METHOD(setGeofeneceMaxCount:(NSDictionary *)params) {
|
|
|
1058
1121
|
[copyData removeObjectForKey:@"_j_uid"];
|
|
1059
1122
|
[copyData removeObjectForKey:@"_j_msgid"];
|
|
1060
1123
|
[copyData removeObjectForKey:@"_j_InternalNotificationName"];
|
|
1124
|
+
[copyData removeObjectForKey:@"_j_InternalPolicyGeneration"];
|
|
1061
1125
|
[copyData removeObjectForKey:@"aps"];
|
|
1062
1126
|
|
|
1063
1127
|
NSMutableDictionary *extrasData = [NSMutableDictionary dictionary];
|
|
@@ -1105,6 +1169,7 @@ RCT_EXPORT_METHOD(setGeofeneceMaxCount:(NSDictionary *)params) {
|
|
|
1105
1169
|
notificationName = internalName.length > 0 ? internalName : J_LOCAL_NOTIFICATION_OPENED_EVENT;
|
|
1106
1170
|
NSMutableDictionary *cleanData = [NSMutableDictionary dictionaryWithDictionary:dictData];
|
|
1107
1171
|
[cleanData removeObjectForKey:@"_j_InternalNotificationName"];
|
|
1172
|
+
[cleanData removeObjectForKey:@"_j_InternalPolicyGeneration"];
|
|
1108
1173
|
objectData = [cleanData copy];
|
|
1109
1174
|
}
|
|
1110
1175
|
NSString *notificationEventType = [notificationName isEqualToString:J_LOCAL_NOTIFICATION_OPENED_EVENT]
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
NS_ASSUME_NONNULL_BEGIN
|
|
11
11
|
|
|
12
|
+
FOUNDATION_EXPORT NSString *const JCOREPolicyDidChangeNotification;
|
|
13
|
+
|
|
12
14
|
@interface JCOREConfiguration : NSObject
|
|
13
15
|
|
|
14
16
|
+ (instancetype)shared;
|
|
@@ -35,6 +37,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
35
37
|
|
|
36
38
|
@property (nonatomic, assign) BOOL collectionAuthorized;
|
|
37
39
|
@property (nonatomic, assign) BOOL pushStopped;
|
|
40
|
+
@property (nonatomic, assign, readonly) NSUInteger policyGeneration;
|
|
41
|
+
@property (nonatomic, assign, readonly) BOOL policyAllowsPush;
|
|
42
|
+
- (BOOL)allowsPolicyGeneration:(NSUInteger)generation;
|
|
38
43
|
@property (nonatomic, assign) BOOL debugEnabled;
|
|
39
44
|
@property (nonatomic, assign) BOOL logOff;
|
|
40
45
|
@property (nonatomic, assign) BOOL localLogEnabled;
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
#import <UIKit/UIKit.h>
|
|
6
6
|
#endif
|
|
7
7
|
|
|
8
|
+
NSString *const JCOREPolicyDidChangeNotification = @"JCOREPolicyDidChangeNotification";
|
|
9
|
+
|
|
8
10
|
static NSString *const kJCoreKeyUid = @"com.onekey.jcore.uid";
|
|
9
11
|
static NSString *const kJCoreKeyPassword = @"com.onekey.jcore.password";
|
|
10
12
|
static NSString *const kJCoreKeyRegistrationId = @"com.onekey.jcore.registration_id";
|
|
@@ -69,6 +71,7 @@ static NSString *const kJCoreKeySisFailedIps = @"com.onekey.jcore.sis.failed_ips
|
|
|
69
71
|
@interface JCOREConfiguration () {
|
|
70
72
|
dispatch_queue_t _stateQueue;
|
|
71
73
|
uint16_t _requestCounter;
|
|
74
|
+
NSUInteger _policyGeneration;
|
|
72
75
|
NSArray<NSString *> *_ips;
|
|
73
76
|
NSArray<NSString *> *_sslIps;
|
|
74
77
|
NSArray<NSString *> *_sisIps;
|
|
@@ -86,6 +89,9 @@ static NSString *const kJCoreKeySisFailedIps = @"com.onekey.jcore.sis.failed_ips
|
|
|
86
89
|
|
|
87
90
|
@implementation JCOREConfiguration
|
|
88
91
|
|
|
92
|
+
@synthesize collectionAuthorized = _collectionAuthorized;
|
|
93
|
+
@synthesize pushStopped = _pushStopped;
|
|
94
|
+
|
|
89
95
|
+ (instancetype)shared {
|
|
90
96
|
static JCOREConfiguration *instance = nil;
|
|
91
97
|
static dispatch_once_t onceToken;
|
|
@@ -191,14 +197,48 @@ static NSString *const kJCoreKeySisFailedIps = @"com.onekey.jcore.sis.failed_ips
|
|
|
191
197
|
self.customConnectAddresses = nil;
|
|
192
198
|
}
|
|
193
199
|
|
|
200
|
+
- (BOOL)collectionAuthorized {
|
|
201
|
+
@synchronized (self) { return _collectionAuthorized; }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
- (BOOL)pushStopped {
|
|
205
|
+
@synchronized (self) { return _pushStopped; }
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
- (NSUInteger)policyGeneration {
|
|
209
|
+
@synchronized (self) { return _policyGeneration; }
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
- (BOOL)policyAllowsPush {
|
|
213
|
+
@synchronized (self) { return _collectionAuthorized && !_pushStopped; }
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
- (BOOL)allowsPolicyGeneration:(NSUInteger)generation {
|
|
217
|
+
@synchronized (self) {
|
|
218
|
+
return _collectionAuthorized && !_pushStopped && _policyGeneration == generation;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
194
222
|
- (void)setCollectionAuthorized:(BOOL)collectionAuthorized {
|
|
195
|
-
|
|
196
|
-
|
|
223
|
+
NSUInteger generation;
|
|
224
|
+
@synchronized (self) {
|
|
225
|
+
if (_collectionAuthorized == collectionAuthorized) { return; }
|
|
226
|
+
_collectionAuthorized = collectionAuthorized;
|
|
227
|
+
generation = ++_policyGeneration;
|
|
228
|
+
[[NSUserDefaults standardUserDefaults] setBool:collectionAuthorized forKey:kJCoreKeyAuth];
|
|
229
|
+
}
|
|
230
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:JCOREPolicyDidChangeNotification object:self userInfo:@{@"generation": @(generation)}];
|
|
197
231
|
}
|
|
198
232
|
|
|
199
233
|
- (void)setPushStopped:(BOOL)pushStopped {
|
|
200
|
-
|
|
201
|
-
|
|
234
|
+
NSUInteger generation;
|
|
235
|
+
@synchronized (self) {
|
|
236
|
+
if (_pushStopped == pushStopped) { return; }
|
|
237
|
+
_pushStopped = pushStopped;
|
|
238
|
+
generation = ++_policyGeneration;
|
|
239
|
+
[[NSUserDefaults standardUserDefaults] setBool:pushStopped forKey:kJCoreKeyPushStopped];
|
|
240
|
+
}
|
|
241
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:JCOREPolicyDidChangeNotification object:self userInfo:@{@"generation": @(generation)}];
|
|
202
242
|
}
|
|
203
243
|
|
|
204
244
|
- (void)setDeviceTokenHex:(NSString *)deviceTokenHex {
|