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+ @implementation OSPendingLiveActivityUpdate
108+
109+ - (id )initWith : (NSString *)activityId
110+ withToken : (NSString *)token
111+ isEnter : (BOOL )isEnter
112+ withSuccess : (OSResultSuccessBlock)successBlock
113+ withFailure : (OSFailureBlock)failureBlock {
114+ self.token = token;
115+ self.activityId = activityId;
116+ self.isEnter = isEnter;
117+ self.successBlock = successBlock;
118+ self.failureBlock = failureBlock;
119+ return self;
120+ };
121+ @end
122+
95123@implementation OneSignal
96124
97125static NSString * mSDKType = @" native" ;
@@ -100,6 +128,8 @@ @implementation OneSignal
100128static OSResultSuccessBlock pendingGetTagsSuccessBlock;
101129static OSFailureBlock pendingGetTagsFailureBlock;
102130
131+ static NSMutableArray * pendingLiveActivityUpdates;
132+
103133// Has attempted to register for push notifications with Apple since app was installed.
104134static BOOL registeredWithApple = NO ;
105135
@@ -363,6 +393,109 @@ + (void)setProvidesNotificationSettingsView:(BOOL)providesView {
363393 }
364394}
365395
396+ #pragma mark: LIVE ACTIVITIES
397+
398+ + (void )enterLiveActivity : (NSString * _Nonnull)activityId withToken : (NSString * _Nonnull)token {
399+
400+ if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName: @" enterLiveActivity:" ])
401+ return ;
402+
403+ [self enterLiveActivity: activityId withToken: token withSuccess: nil withFailure: nil ];
404+ }
405+
406+ + (void )enterLiveActivity : (NSString * _Nonnull)activityId withToken : (NSString * _Nonnull)token withSuccess : (OSResultSuccessBlock _Nullable)successBlock withFailure : (OSFailureBlock _Nullable)failureBlock {
407+
408+ if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName: @" enterLiveActivity:onSuccess:onFailure:" ]) {
409+ if (failureBlock) {
410+ NSError *error = [NSError errorWithDomain: @" com.onesignal.tags" code: 0 userInfo: @{@" error" : @" Your application has called enterLiveActivity:onSuccess:onFailure: before the user granted privacy permission. Please call `consentGranted(bool)` in order to provide user privacy consent" }];
411+ failureBlock (error);
412+ }
413+ return ;
414+ }
415+
416+
417+ if (self.currentSubscriptionState .userId ) {
418+ [OneSignalClient.sharedClient executeRequest: [OSRequestLiveActivityEnter withUserId: self .currentSubscriptionState.userId appId: appId activityId: activityId token: token]
419+ onSuccess: ^(NSDictionary *result) {
420+ [self callSuccessBlockOnMainThread: successBlock withResult: result];
421+ } onFailure: ^(NSError *error) {
422+ [self callFailureBlockOnMainThread: failureBlock withError: error];
423+ }];
424+ } else {
425+ [self addPendingLiveActivityUpdate: activityId withToken: token isEnter: true withSuccess: successBlock withFailure: failureBlock];
426+ }
427+ }
428+
429+ + (void )exitLiveActivity : (NSString * _Nonnull)activityId {
430+
431+ if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName: @" enterLiveActivity:" ])
432+ return ;
433+
434+ [self exitLiveActivity: activityId withSuccess: nil withFailure: nil ];
435+ }
436+
437+ + (void )exitLiveActivity : (NSString * _Nonnull)activityId withSuccess : (OSResultSuccessBlock _Nullable)successBlock withFailure : (OSFailureBlock _Nullable)failureBlock {
438+
439+ if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName: @" exitLiveActivity:onSuccess:onFailure:" ]) {
440+ if (failureBlock) {
441+ NSError *error = [NSError errorWithDomain: @" com.onesignal.tags" code: 0 userInfo: @{@" error" : @" Your application has called exitLiveActivity:onSuccess:onFailure: before the user granted privacy permission. Please call `consentGranted(bool)` in order to provide user privacy consent" }];
442+ failureBlock (error);
443+ }
444+ return ;
445+ }
446+ if (self.currentSubscriptionState .userId ) {
447+ [OneSignalClient.sharedClient executeRequest: [OSRequestLiveActivityExit withUserId: self .currentSubscriptionState.userId appId: appId activityId: activityId]
448+ onSuccess: ^(NSDictionary *result) {
449+ [self callSuccessBlockOnMainThread: successBlock withResult: result];
450+ } onFailure: ^(NSError *error) {
451+ [self callFailureBlockOnMainThread: failureBlock withError: error];
452+ }];
453+ } else {
454+ [self addPendingLiveActivityUpdate: activityId withToken: nil isEnter: false withSuccess: successBlock withFailure: failureBlock];
455+ }
456+ }
457+
458+ + (void )addPendingLiveActivityUpdate : (NSString * _Nonnull)activityId
459+ withToken : (NSString * _Nullable)token
460+ isEnter : (BOOL )isEnter
461+ withSuccess : (OSResultSuccessBlock _Nullable)successBlock
462+ withFailure : (OSFailureBlock _Nullable)failureBlock {
463+ OSPendingLiveActivityUpdate *pendingLiveActivityUpdate = [[OSPendingLiveActivityUpdate alloc ] initWith: activityId withToken: token isEnter: isEnter withSuccess: successBlock withFailure: failureBlock];
464+
465+ if (!pendingLiveActivityUpdates) {
466+ pendingLiveActivityUpdates = [NSMutableArray new ];
467+ }
468+ [pendingLiveActivityUpdates addObject: pendingLiveActivityUpdate];
469+ }
470+
471+ + (void )executePendingLiveActivityUpdates {
472+ if (pendingLiveActivityUpdates.count <= 0 ) {
473+ return ;
474+ }
475+
476+ OSPendingLiveActivityUpdate * updateToProcess = [pendingLiveActivityUpdates objectAtIndex: 0 ];
477+ [pendingLiveActivityUpdates removeObjectAtIndex: 0 ];
478+ if (updateToProcess.isEnter ) {
479+ [OneSignalClient.sharedClient executeRequest: [OSRequestLiveActivityEnter withUserId: self .currentSubscriptionState.userId appId: appId activityId: updateToProcess.activityId token: updateToProcess.token]
480+ onSuccess: ^(NSDictionary *result) {
481+ [self callSuccessBlockOnMainThread: updateToProcess.successBlock withResult: result];
482+ [self executePendingLiveActivityUpdates ];
483+ } onFailure: ^(NSError *error) {
484+ [self callFailureBlockOnMainThread: updateToProcess.failureBlock withError: error];
485+ [self executePendingLiveActivityUpdates ];
486+ }];
487+ } else {
488+ [OneSignalClient.sharedClient executeRequest: [OSRequestLiveActivityExit withUserId: self .currentSubscriptionState.userId appId: appId activityId: updateToProcess.activityId]
489+ onSuccess: ^(NSDictionary *result) {
490+ [self callSuccessBlockOnMainThread: updateToProcess.successBlock withResult: result];
491+ [self executePendingLiveActivityUpdates ];
492+ } onFailure: ^(NSError *error) {
493+ [self callFailureBlockOnMainThread: updateToProcess.failureBlock withError: error];
494+ [self executePendingLiveActivityUpdates ];
495+ }];
496+ }
497+ }
498+
366499#pragma mark Initialization
367500
368501+ (BOOL )shouldStartNewSession {
0 commit comments