diff options
author | Benoit St-Pierre <bstpierre@google.com> | 2018-02-26 11:23:44 -0500 |
---|---|---|
committer | Benoit St-Pierre <bstpierre@google.com> | 2018-02-26 11:23:44 -0500 |
commit | f851ca9ffaf4dd9fd6b78ce5c96305c42e8651eb (patch) | |
tree | c02e34355679e3a5c35739447185523bd07c2abc /Firebase/Core/FIRApp.m | |
parent | dfda142503e0daffeab67e996df03324e1f372b3 (diff) |
Add third-party library version registration
This will allow us to collect the version of platform libraries that
developers use in conjunction with Firebase.
Diffstat (limited to 'Firebase/Core/FIRApp.m')
-rw-r--r-- | Firebase/Core/FIRApp.m | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Firebase/Core/FIRApp.m b/Firebase/Core/FIRApp.m index 22c9369..d8ff75d 100644 --- a/Firebase/Core/FIRApp.m +++ b/Firebase/Core/FIRApp.m @@ -84,6 +84,7 @@ static NSString *const kPlistURL = @"https://console.firebase.google.com/"; static NSMutableDictionary *sAllApps; static FIRApp *sDefaultApp; +static NSMutableDictionary *sLibraryVersions; + (void)configure { FIROptions *options = [FIROptions defaultOptions]; @@ -400,6 +401,41 @@ static FIRApp *sDefaultApp; return (sDefaultApp != nil); } ++ (void)registerLibrary:(nonnull NSString *)library withVersion:(nonnull NSString *)version { + // Create the set of characters which aren't allowed, only if this feature is used. + static NSCharacterSet *disallowedSet; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSMutableCharacterSet *allowedSet = [NSMutableCharacterSet alphanumericCharacterSet]; + [allowedSet addCharactersInString:@"-_."]; + disallowedSet = [allowedSet invertedSet]; + }); + // Make sure the library name and version strings do not contain unexpected characters, and + // add the name/version pair to the dictionary. + if ([library rangeOfCharacterFromSet:disallowedSet].location == NSNotFound && + [version rangeOfCharacterFromSet:disallowedSet].location == NSNotFound) { + if (!sLibraryVersions) { + sLibraryVersions = [[NSMutableDictionary alloc] init]; + } + sLibraryVersions[library] = version; + } else { + FIRLogError(kFIRLoggerCore, @"I-COR000027", + @"The library name (%@) or version number (%@) contain illegal characters. " + @"Only alphanumeric, dash, underscore and period characters are allowed.", + library, version); + } +} + ++ (NSString *)firebaseUserAgent { + NSMutableArray<NSString *> *libraries = + [[NSMutableArray<NSString *> alloc] initWithCapacity:sLibraryVersions.count]; + for (NSString *libraryName in sLibraryVersions) { + [libraries addObject: + [NSString stringWithFormat:@"%@/%@", libraryName, sLibraryVersions[libraryName]]]; + } + return [libraries componentsJoinedByString:@" "]; +} + - (void)checkExpectedBundleID { NSArray *bundles = [FIRBundleUtil relevantBundles]; NSString *expectedBundleID = [self expectedBundleID]; |