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 | |
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')
-rw-r--r-- | Firebase/Core/FIRApp.m | 36 | ||||
-rw-r--r-- | Firebase/Core/Private/FIRAppInternal.h | 16 |
2 files changed, 52 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]; diff --git a/Firebase/Core/Private/FIRAppInternal.h b/Firebase/Core/Private/FIRAppInternal.h index 447d151..bbf0477 100644 --- a/Firebase/Core/Private/FIRAppInternal.h +++ b/Firebase/Core/Private/FIRAppInternal.h @@ -134,6 +134,22 @@ typedef NSString *_Nullable (^FIRAppGetUIDImplementation)(void); */ + (BOOL)isDefaultAppConfigured; + +/** + * Registers a given third-party library with the given version number to be reported for + * analyitcs. + * + * @param library Name of the library + * @param version Version of the library + */ ++ (void)registerLibrary:(nonnull NSString *)library withVersion:(nonnull NSString *)version \ + NS_SWIFT_NAME(registerLibrary(_:version:)); + +/** + * A concatenated string representing all the third-party libraries and version numbers. + */ ++ (NSString *)firebaseUserAgent; + /** * Used by each SDK to send logs about SDK configuration status to Clearcut. */ |