35
35
36
36
#import " FirebaseCore/Extension/FirebaseCoreInternal.h"
37
37
38
- @interface FPRClient ()
38
+ @interface FPRClient () <FIRLibrary, FIRPerformanceProvider>
39
39
40
40
/* * The original configuration object used to initialize the client. */
41
41
@property (nonatomic , strong ) FPRConfiguration *config;
@@ -48,22 +48,26 @@ @interface FPRClient ()
48
48
@implementation FPRClient
49
49
50
50
+ (void )load {
51
- __weak NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter ];
52
- __block id listener;
53
-
54
- void (^observerBlock)(NSNotification *) = ^(NSNotification *aNotification) {
55
- NSDictionary *appInfoDict = aNotification.userInfo ;
56
- NSNumber *isDefaultApp = appInfoDict[kFIRAppIsDefaultAppKey ];
57
- if (![isDefaultApp boolValue ]) {
58
- return ;
51
+ [FIRApp registerInternalLibrary: [FPRClient class ]
52
+ withName: @" fire-perf"
53
+ withVersion: [NSString stringWithUTF8String: kFPRSDKVersion ]];
54
+ }
55
+
56
+ #pragma mark - Component registration system
57
+
58
+ + (nonnull NSArray <FIRComponent *> *)componentsToRegister {
59
+ FIRComponentCreationBlock creationBlock =
60
+ ^id _Nullable (FIRComponentContainer *container, BOOL *isCacheable) {
61
+ if (!container.app .isDefaultApp ) {
62
+ return nil ;
59
63
}
60
64
61
- NSString *appName = appInfoDict[ kFIRAppNameKey ] ;
65
+ NSString *appName = container. app . name ;
62
66
FIRApp *app = [FIRApp appNamed: appName];
63
67
FIROptions *options = app.options ;
64
68
NSError *error = nil ;
65
69
66
- // Based on the environment variable SDK decides if events are dispatchd to Autopush or Prod.
70
+ // Based on the environment variable SDK decides if events are dispatched to Autopush or Prod.
67
71
// By default, events are sent to Prod.
68
72
BOOL useAutoPush = NO ;
69
73
NSDictionary <NSString *, NSString *> *environment = [NSProcessInfo processInfo ].environment ;
@@ -79,17 +83,18 @@ + (void)load {
79
83
FPRLogError (kFPRClientInitialize , @" Failed to initialize the client with error: %@ ." , error);
80
84
}
81
85
82
- [notificationCenter removeObserver: listener];
83
- listener = nil ;
86
+ *isCacheable = YES ;
87
+
88
+ return [self sharedInstance ];
84
89
};
85
90
86
- // Register the Perf library for Firebase Core tracking.
87
- [FIRApp registerLibrary: @" fire-perf " // From go/firebase-sdk-platform-info
88
- withVersion: [ NSString stringWithUTF8String: kFPRSDKVersion ]];
89
- listener = [notificationCenter addObserverForName: kFIRAppReadyToConfigureSDKNotification
90
- object: [FIRApp class ]
91
- queue: nil
92
- usingBlock: observerBlock ];
91
+ FIRComponent *component =
92
+ [FIRComponent componentWithProtocol: @protocol (FIRPerformanceProvider)
93
+ instantiationTiming: FIRInstantiationTimingEagerInDefaultApp
94
+ dependencies: @[]
95
+ creationBlock: creationBlock];
96
+
97
+ return @[ component ];
93
98
}
94
99
95
100
+ (FPRClient *)sharedInstance {
0 commit comments