FIRCoreDiagnosticsConnector.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FirebaseCore/Sources/Private/FIRCoreDiagnosticsConnector.h"
  17. #import "Interop/CoreDiagnostics/Public/FIRCoreDiagnosticsInterop.h"
  18. #import "FirebaseCore/Sources/Public/FIROptions.h"
  19. #import "FirebaseCore/Sources/FIRDiagnosticsData.h"
  20. #import "FirebaseCore/Sources/Private/FIRAppInternal.h"
  21. #import "FirebaseCore/Sources/Private/FIROptionsInternal.h"
  22. // Define the interop class symbol declared as an extern in FIRCoreDiagnosticsInterop.
  23. Class<FIRCoreDiagnosticsInterop> FIRCoreDiagnosticsImplementation;
  24. @implementation FIRCoreDiagnosticsConnector
  25. + (void)initialize {
  26. if (!FIRCoreDiagnosticsImplementation) {
  27. FIRCoreDiagnosticsImplementation = NSClassFromString(@"FIRCoreDiagnostics");
  28. if (FIRCoreDiagnosticsImplementation) {
  29. NSAssert([FIRCoreDiagnosticsImplementation
  30. conformsToProtocol:@protocol(FIRCoreDiagnosticsInterop)],
  31. @"If FIRCoreDiagnostics is implemented, it must conform to the interop protocol.");
  32. NSAssert(
  33. [FIRCoreDiagnosticsImplementation respondsToSelector:@selector(sendDiagnosticsData:)],
  34. @"If FIRCoreDiagnostics is implemented, it must implement +sendDiagnosticsData.");
  35. }
  36. }
  37. }
  38. + (void)logCoreTelemetryWithOptions:(FIROptions *)options {
  39. if (FIRCoreDiagnosticsImplementation) {
  40. FIRDiagnosticsData *diagnosticsData = [[FIRDiagnosticsData alloc] init];
  41. [diagnosticsData insertValue:@(YES) forKey:kFIRCDIsDataCollectionDefaultEnabledKey];
  42. [diagnosticsData insertValue:[FIRApp firebaseUserAgent] forKey:kFIRCDFirebaseUserAgentKey];
  43. [diagnosticsData insertValue:@(FIRConfigTypeCore) forKey:kFIRCDConfigurationTypeKey];
  44. [diagnosticsData insertValue:options.googleAppID forKey:kFIRCDGoogleAppIDKey];
  45. [diagnosticsData insertValue:options.bundleID forKey:kFIRCDBundleIDKey];
  46. [diagnosticsData insertValue:@(options.usingOptionsFromDefaultPlist)
  47. forKey:kFIRCDUsingOptionsFromDefaultPlistKey];
  48. [diagnosticsData insertValue:options.libraryVersionID forKey:kFIRCDLibraryVersionIDKey];
  49. [FIRCoreDiagnosticsImplementation sendDiagnosticsData:diagnosticsData];
  50. }
  51. }
  52. @end