@@ -166,9 +166,11 @@ + (void)configureWithName:(NSString *)name options:(FIROptions *)options {
166
166
}
167
167
}
168
168
169
- if (sAllApps && sAllApps [name]) {
170
- [NSException raise: kFirebaseCoreErrorDomain
171
- format: @" App named %@ has already been configured." , name];
169
+ @synchronized (self) {
170
+ if (sAllApps && sAllApps [name]) {
171
+ [NSException raise: kFirebaseCoreErrorDomain
172
+ format: @" App named %@ has already been configured." , name];
173
+ }
172
174
}
173
175
174
176
FIRLogDebug (kFIRLoggerCore , @" I-COR000002" , @" Configuring app named %@ " , name);
@@ -214,18 +216,19 @@ + (NSDictionary *)allApps {
214
216
if (!sAllApps ) {
215
217
FIRLogError (kFIRLoggerCore , @" I-COR000005" , @" No app has been configured yet." );
216
218
}
217
- NSDictionary *dict = [NSDictionary dictionaryWithDictionary: sAllApps ];
218
- return dict;
219
+ return [sAllApps copy ];
219
220
}
220
221
}
221
222
222
223
// Public only for tests
223
224
+ (void )resetApps {
224
- sDefaultApp = nil ;
225
- [sAllApps removeAllObjects ];
226
- sAllApps = nil ;
227
- [sLibraryVersions removeAllObjects ];
228
- sLibraryVersions = nil ;
225
+ @synchronized (self) {
226
+ sDefaultApp = nil ;
227
+ [sAllApps removeAllObjects ];
228
+ sAllApps = nil ;
229
+ [sLibraryVersions removeAllObjects ];
230
+ sLibraryVersions = nil ;
231
+ }
229
232
}
230
233
231
234
- (void )deleteApp : (FIRAppVoidBoolCallback)completion {
@@ -423,8 +426,10 @@ + (void)sendNotificationsToSDKs:(FIRApp *)app {
423
426
424
427
// This is the new way of sending information to SDKs.
425
428
// TODO: Do we want this on a background thread, maybe?
426
- for (Class <FIRLibrary> library in sRegisteredAsConfigurable ) {
427
- [library configureWithApp: app];
429
+ @synchronized (self) {
430
+ for (Class <FIRLibrary> library in sRegisteredAsConfigurable ) {
431
+ [library configureWithApp: app];
432
+ }
428
433
}
429
434
}
430
435
@@ -476,10 +481,12 @@ + (void)registerLibrary:(nonnull NSString *)name withVersion:(nonnull NSString *
476
481
// add the name/version pair to the dictionary.
477
482
if ([name rangeOfCharacterFromSet: disallowedSet].location == NSNotFound &&
478
483
[version rangeOfCharacterFromSet: disallowedSet].location == NSNotFound ) {
479
- if (!sLibraryVersions ) {
480
- sLibraryVersions = [[NSMutableDictionary alloc ] init ];
484
+ @synchronized (self) {
485
+ if (!sLibraryVersions ) {
486
+ sLibraryVersions = [[NSMutableDictionary alloc ] init ];
487
+ }
488
+ sLibraryVersions [name] = version;
481
489
}
482
- sLibraryVersions [name] = version;
483
490
} else {
484
491
FIRLogError (kFIRLoggerCore , @" I-COR000027" ,
485
492
@" The library name (%@ ) or version number (%@ ) contain invalid characters. "
@@ -508,20 +515,24 @@ + (void)registerInternalLibrary:(nonnull Class<FIRLibrary>)library
508
515
dispatch_once (&onceToken, ^{
509
516
sRegisteredAsConfigurable = [[NSMutableArray alloc ] init ];
510
517
});
511
- [sRegisteredAsConfigurable addObject: library];
518
+ @synchronized (self) {
519
+ [sRegisteredAsConfigurable addObject: library];
520
+ }
512
521
}
513
522
[self registerLibrary: name withVersion: version];
514
523
}
515
524
516
525
+ (NSString *)firebaseUserAgent {
517
- NSMutableArray <NSString *> *libraries =
518
- [[NSMutableArray <NSString *> alloc] initWithCapacity: sLibraryVersions .count];
519
- for (NSString *libraryName in sLibraryVersions ) {
520
- [libraries
521
- addObject: [NSString stringWithFormat: @" %@ /%@ " , libraryName, sLibraryVersions [libraryName]]];
522
- }
523
- [libraries sortUsingSelector: @selector (localizedCaseInsensitiveCompare: )];
524
- return [libraries componentsJoinedByString: @" " ];
526
+ @synchronized (self) {
527
+ NSMutableArray <NSString *> *libraries =
528
+ [[NSMutableArray <NSString *> alloc] initWithCapacity: sLibraryVersions .count];
529
+ for (NSString *libraryName in sLibraryVersions ) {
530
+ [libraries addObject: [NSString stringWithFormat: @" %@ /%@ " , libraryName,
531
+ sLibraryVersions [libraryName]]];
532
+ }
533
+ [libraries sortUsingSelector: @selector (localizedCaseInsensitiveCompare: )];
534
+ return [libraries componentsJoinedByString: @" " ];
535
+ }
525
536
}
526
537
527
538
- (void )checkExpectedBundleID {
0 commit comments