9292@interface OneSignal (SessionStatusDelegate)
9393@end
9494
95- @interface OSPendingLiveActivityUpdate : NSObject
96- @property NSString * token;
97- @property NSString * activityId;
98- @property BOOL isEnter;
99- @property OSResultSuccessBlock successBlock;
100- @property OSFailureBlock failureBlock;
101- - (id )initWith:(NSString * _Nonnull)activityId
102- withToken:(NSString * _Nonnull)token
103- isEnter:(BOOL )isEnter
104- withSuccess:(OSResultSuccessBlock _Nullable)successBlock
105- withFailure:(OSFailureBlock _Nullable)failureBlock;
106- @end
107-
108- @implementation OSPendingLiveActivityUpdate
109-
110- - (id )initWith : (NSString *)activityId
111- withToken : (NSString *)token
112- isEnter : (BOOL )isEnter
113- withSuccess : (OSResultSuccessBlock)successBlock
114- withFailure : (OSFailureBlock)failureBlock {
115- self.token = token;
116- self.activityId = activityId;
117- self.isEnter = isEnter;
118- self.successBlock = successBlock;
119- self.failureBlock = failureBlock;
120- return self;
121- };
122- @end
123-
124- @interface OSSubscriptionObserver : NSObject <OSPushSubscriptionObserver>
125- @end
126-
127- @implementation OSSubscriptionObserver
128-
129- - (void )onOSPushSubscriptionChangedWithStateChanges : (OSPushSubscriptionStateChanges * _Nonnull)stateChanges {
130- if (stateChanges.to .id ){
131- [OneSignal executePendingLiveActivityUpdates ];
132- }
133- }
134- @end
135-
13695@implementation OneSignal
13796
13897static NSString * mSDKType = @" native" ;
13998
140- static NSMutableArray * pendingLiveActivityUpdates;
141- static OSSubscriptionObserver* _subscriptionObserver;
142-
14399// Has attempted to register for push notifications with Apple since app was installed.
144100static BOOL registeredWithApple = NO ;
145101
@@ -168,8 +124,6 @@ + (DelayedConsentInitializationParameters *)delayedInitParameters {
168124
169125static LanguageContext* languageContext;
170126
171- static NSString * subscriptionId;
172-
173127// static property def to add developer's OSPermissionStateChanges observers to.
174128static ObservablePermissionStateChangesType* _permissionStateChangesObserver;
175129+ (ObservablePermissionStateChangesType*)permissionStateChangesObserver {
@@ -412,18 +366,8 @@ + (void)enterLiveActivity:(NSString * _Nonnull)activityId withToken:(NSString *
412366 }
413367 return ;
414368 }
415-
416- if (subscriptionId) {
417- [OneSignalClient.sharedClient executeRequest: [OSRequestLiveActivityEnter withUserId: subscriptionId appId: appId activityId: activityId token: token]
418- onSuccess: ^(NSDictionary *result) {
419- [self callSuccessBlockOnMainThread: successBlock withResult: result];
420- } onFailure: ^(NSError *error) {
421- [self callFailureBlockOnMainThread: failureBlock withError: error];
422- }];
423- } else {
424- _subscriptionObserver = [OSSubscriptionObserver new ];
425- [self addPendingLiveActivityUpdate: activityId withToken: token isEnter: true withSuccess: successBlock withFailure: failureBlock];
426- }
369+
370+ [OneSignalLiveActivityController enterLiveActivity: activityId appId: appId withToken: token withSuccess: successBlock withFailure: failureBlock];
427371}
428372
429373+ (void )exitLiveActivity : (NSString * _Nonnull)activityId {
@@ -444,76 +388,9 @@ + (void)exitLiveActivity:(NSString * _Nonnull)activityId withSuccess:(OSResultSu
444388 return ;
445389 }
446390
447- if (subscriptionId) {
448- [OneSignalClient.sharedClient executeRequest: [OSRequestLiveActivityExit withUserId: subscriptionId appId: appId activityId: activityId]
449- onSuccess: ^(NSDictionary *result) {
450- [self callSuccessBlockOnMainThread: successBlock withResult: result];
451- } onFailure: ^(NSError *error) {
452- [self callFailureBlockOnMainThread: failureBlock withError: error];
453- }];
454- } else {
455- _subscriptionObserver = [OSSubscriptionObserver new ];
456- [self addPendingLiveActivityUpdate: activityId withToken: nil isEnter: false withSuccess: successBlock withFailure: failureBlock];
457- }
391+ [OneSignalLiveActivityController exitLiveActivity: activityId appId: appId withSuccess: successBlock withFailure: failureBlock];
458392}
459393
460- + (void )callFailureBlockOnMainThread : (OSFailureBlock)failureBlock withError : (NSError *)error {
461- if (failureBlock) {
462- dispatch_async (dispatch_get_main_queue (), ^{
463- failureBlock (error);
464- });
465- }
466- }
467-
468- + (void )callSuccessBlockOnMainThread : (OSResultSuccessBlock)successBlock withResult : (NSDictionary *)result {
469- if (successBlock) {
470- dispatch_async (dispatch_get_main_queue (), ^{
471- successBlock (result);
472- });
473- }
474- }
475-
476- + (void )addPendingLiveActivityUpdate : (NSString * _Nonnull)activityId
477- withToken : (NSString * _Nullable)token
478- isEnter : (BOOL )isEnter
479- withSuccess : (OSResultSuccessBlock _Nullable)successBlock
480- withFailure : (OSFailureBlock _Nullable)failureBlock {
481- OSPendingLiveActivityUpdate *pendingLiveActivityUpdate = [[OSPendingLiveActivityUpdate alloc ] initWith: activityId withToken: token isEnter: isEnter withSuccess: successBlock withFailure: failureBlock];
482-
483- if (!pendingLiveActivityUpdates) {
484- pendingLiveActivityUpdates = [NSMutableArray new ];
485- }
486- [pendingLiveActivityUpdates addObject: pendingLiveActivityUpdate];
487- }
488-
489- + (void )executePendingLiveActivityUpdates {
490- subscriptionId = OneSignalUserManagerImpl.sharedInstance .pushSubscriptionId ;
491- if (pendingLiveActivityUpdates.count <= 0 ) {
492- return ;
493- }
494-
495- OSPendingLiveActivityUpdate * updateToProcess = [pendingLiveActivityUpdates objectAtIndex: 0 ];
496- [pendingLiveActivityUpdates removeObjectAtIndex: 0 ];
497- if (updateToProcess.isEnter ) {
498- [OneSignalClient.sharedClient executeRequest: [OSRequestLiveActivityEnter withUserId: subscriptionId appId: appId activityId: updateToProcess.activityId token: updateToProcess.token]
499- onSuccess: ^(NSDictionary *result) {
500- [self callSuccessBlockOnMainThread: updateToProcess.successBlock withResult: result];
501- [self executePendingLiveActivityUpdates ];
502- } onFailure: ^(NSError *error) {
503- [self callFailureBlockOnMainThread: updateToProcess.failureBlock withError: error];
504- [self executePendingLiveActivityUpdates ];
505- }];
506- } else {
507- [OneSignalClient.sharedClient executeRequest: [OSRequestLiveActivityExit withUserId: subscriptionId appId: appId activityId: updateToProcess.activityId]
508- onSuccess: ^(NSDictionary *result) {
509- [self callSuccessBlockOnMainThread: updateToProcess.successBlock withResult: result];
510- [self executePendingLiveActivityUpdates ];
511- } onFailure: ^(NSError *error) {
512- [self callFailureBlockOnMainThread: updateToProcess.failureBlock withError: error];
513- [self executePendingLiveActivityUpdates ];
514- }];
515- }
516- }
517394
518395#pragma mark Initialization
519396
@@ -720,8 +597,6 @@ + (void)init {
720597 [self startInAppMessages ];
721598 [self startNewSession: YES ];
722599
723- subscriptionId = OneSignalUserManagerImpl.sharedInstance .pushSubscriptionId ;
724-
725600 initializationTime = [[NSDate date ] timeIntervalSince1970 ];
726601 initDone = true ;
727602}
0 commit comments