File tree Expand file tree Collapse file tree
SalesforceAnalytics/SalesforceAnalytics/Classes/Store
SalesforceSDKCore/SalesforceSDKCore/Classes/UserAccount Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,10 +69,12 @@ - (instancetype) initWithStoreDirectory:(NSString *) storeDirectory dataEncrypto
6969
7070 // Gets current number of events stored.
7171 self.eventCountMutex = [[NSObject alloc ] init ];
72- self.numStoredEvents = 0 ;
73- NSArray *files = [[NSFileManager defaultManager ] contentsOfDirectoryAtPath: self .storeDirectory error: nil ];
74- if (files) {
75- self.numStoredEvents = files.count ;
72+ @synchronized (self.eventCountMutex ) {
73+ self.numStoredEvents = 0 ;
74+ NSArray *files = [[NSFileManager defaultManager ] contentsOfDirectoryAtPath: self .storeDirectory error: nil ];
75+ if (files) {
76+ self.numStoredEvents = files.count ;
77+ }
7678 }
7779 }
7880 return self;
@@ -198,7 +200,11 @@ - (void) deleteAllEvents {
198200}
199201
200202- (BOOL ) shouldStoreEvent {
201- return (self.isLoggingEnabled && (self.numStoredEvents < self.maxEvents ));
203+ BOOL result;
204+ @synchronized (self.eventCountMutex ) {
205+ result = (self.isLoggingEnabled && (self.numStoredEvents < self.maxEvents ));
206+ }
207+ return result;
202208}
203209
204210- (BOOL ) isLoggingEnabled {
Original file line number Diff line number Diff line change @@ -397,7 +397,15 @@ - (void)kickOffIDPInitiatedLoginFlowForSP:(SFSDKSPConfig *)config statusUpdate:(
397397}
398398
399399- (BOOL )loginWithCompletion : (SFUserAccountManagerSuccessCallbackBlock)completionBlock failure : (SFUserAccountManagerFailureCallbackBlock)failureBlock {
400- BOOL result = NO ;
400+ __block BOOL result = NO ;
401+ if (![NSThread isMainThread ]) {
402+ dispatch_async (dispatch_get_main_queue (), ^{
403+ result = [self loginWithCompletion: completionBlock failure: failureBlock];
404+ });
405+
406+ return result;
407+ }
408+
401409 for (UIScene *scene in [SFApplicationHelper sharedApplication ].connectedScenes ) {
402410 result |= [self loginWithCompletion: completionBlock failure: failureBlock scene: scene];
403411 }
@@ -1219,7 +1227,11 @@ - (BOOL)handleAdvancedAuthURL:(NSURL *)advancedAuthURL options:(NSDictionary *)o
12191227
12201228#pragma mark Account management
12211229- (NSArray *)allUserAccounts {
1222- return [self .userAccountMap allValues ];
1230+ NSArray *accounts = nil ;
1231+ [_accountsLock lock ];
1232+ accounts = [self .userAccountMap allValues ];
1233+ [_accountsLock unlock ];
1234+ return accounts;
12231235}
12241236
12251237- (NSArray *)allUserIdentities {
You can’t perform that action at this time.
0 commit comments