Skip to content

Commit 04fe227

Browse files
committed
PR feedback from Nan, add logging and add controller as observer
1 parent 8e7e611 commit 04fe227

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalLiveActivityController.m

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88

99
#import <Foundation/Foundation.h>
10-
#import <OneSignalCore/OneSignalCore.h>
11-
10+
#import <OneSignalFramework.h>
11+
#import <OneSignalUser/OneSignalUser-Swift.h>
1212
#import "OneSignalLiveActivityController.h"
1313

1414
@interface OSPendingLiveActivityUpdate: NSObject
@@ -49,8 +49,21 @@ @implementation OneSignalLiveActivityController
4949
static NSMutableArray* pendingLiveActivityUpdates;
5050
static NSString* subscriptionId;
5151

52+
static OneSignalLiveActivityController *sharedInstance = nil;
53+
static dispatch_once_t once;
54+
+ (OneSignalLiveActivityController *)sharedInstance {
55+
dispatch_once(&once, ^{
56+
sharedInstance = [OneSignalLiveActivityController new];
57+
});
58+
return sharedInstance;
59+
}
5260
+ (void) initialize {
5361
subscriptionId = OneSignalUserManagerImpl.sharedInstance.pushSubscriptionId;
62+
OneSignalLiveActivityController *shared = OneSignalLiveActivityController.sharedInstance;
63+
#pragma clang diagnostic push
64+
#pragma clang diagnostic ignored "-Wunused-variable"
65+
OSPushSubscriptionState *_ = [OneSignalUserManagerImpl.sharedInstance addObserver:shared];
66+
#pragma clang diagnostic pop
5467
}
5568

5669
- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges * _Nonnull)stateChanges {
@@ -61,6 +74,7 @@ - (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChan
6174
}
6275

6376
+ (void)enterLiveActivity:(NSString * _Nonnull)activityId appId:(NSString *)appId withToken:(NSString * _Nonnull)token withSuccess:(OSResultSuccessBlock _Nullable)successBlock withFailure:(OSFailureBlock _Nullable)failureBlock{
77+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"enterLiveActivity called with activityId: %@ token: %@", activityId, token]];
6478

6579
if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName:@"enterLiveActivity:onSuccess:onFailure:"]) {
6680
if (failureBlock) {
@@ -83,7 +97,7 @@ + (void)enterLiveActivity:(NSString * _Nonnull)activityId appId:(NSString *)appI
8397
}
8498

8599
+ (void)exitLiveActivity:(NSString * _Nonnull)activityId appId:(NSString *)appId withSuccess:(OSResultSuccessBlock _Nullable)successBlock withFailure:(OSFailureBlock _Nullable)failureBlock{
86-
100+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"exitLiveActivity called with activityId: %@", activityId]];
87101
if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName:@"exitLiveActivity:onSuccess:onFailure:"]) {
88102
if (failureBlock) {
89103
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"}];
@@ -126,6 +140,7 @@ + (void)addPendingLiveActivityUpdate:(NSString * _Nonnull)activityId
126140
isEnter:(BOOL)isEnter
127141
withSuccess:(OSResultSuccessBlock _Nullable)successBlock
128142
withFailure:(OSFailureBlock _Nullable)failureBlock {
143+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"addPendingLiveActivityUpdate called with activityId: %@", activityId]];
129144
OSPendingLiveActivityUpdate *pendingLiveActivityUpdate = [[OSPendingLiveActivityUpdate alloc] initWith:activityId appId:appId withToken:token isEnter:isEnter withSuccess:successBlock withFailure:failureBlock];
130145

131146
if (!pendingLiveActivityUpdates) {
@@ -136,6 +151,7 @@ + (void)addPendingLiveActivityUpdate:(NSString * _Nonnull)activityId
136151

137152
+ (void)executePendingLiveActivityUpdates {
138153
subscriptionId = OneSignalUserManagerImpl.sharedInstance.pushSubscriptionId;
154+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"executePendingLiveActivityUpdates called with subscriptionId: %@", subscriptionId]];
139155
if(pendingLiveActivityUpdates.count <= 0) {
140156
return;
141157
}

0 commit comments

Comments
 (0)