1515@import Firebase;
1616
1717static Firestack *_sharedInstance = nil ;
18+ static dispatch_once_t * onceToken;
1819
1920@implementation Firestack
2021
@@ -29,37 +30,27 @@ - (void)dealloc
2930- (instancetype ) init {
3031 self = [super init ];
3132 if (self) {
32- NSLog (@" Initializing Firestack: %@ " , self);
33- [Firestack initializeFirestack: self ];
33+ dispatch_once (&onceToken, ^{
34+ NSLog (@" Initializing Firestack: %@ " , self);
35+ [Firestack initializeFirestack: self ];
36+ });
3437 }
3538 return self;
3639}
3740
3841+ (void ) initializeFirestack : (Firestack *) instance
3942{
40- NSLog (@" Shared instance created on Firestack: %@ " , instance);
41- // [FIRApp configureWithOptions:finalOptions];
42-
4343 _sharedInstance = instance;
4444
45- [[NSNotificationCenter defaultCenter ]
46- postNotificationName: kFirestackInitialized
47- object: [instance getConfig ]];
48-
4945 [[NSNotificationCenter defaultCenter ] addObserver: self
5046 selector: @selector (reloadFirestack )
5147 name: RCTReloadNotification
5248 object: nil ];
5349
54- // [[NSNotificationCenter defaultCenter]
55- // postNotificationName:RCTReloadNotification
56- // object:nil
57- // userInfo:nil];
50+ [[NSNotificationCenter defaultCenter ]
51+ postNotificationName: kFirestackInitialized
52+ object: nil ];
5853
59- // [[NSNotificationCenter defaultCenter] addObserver:self
60- // selector:@selector(firestackConfigured:)
61- // name:kFirestackInitialized
62- // object:instance];
6354}
6455
6556+ (instancetype ) sharedInstance
@@ -70,6 +61,7 @@ + (instancetype) sharedInstance
7061+ (void ) reloadFirestack
7162{
7263 // Reloading firestack
64+ onceToken = 0 ; // not sure if this is a good idea or a bad idea...
7365 [[Firestack sharedInstance ] debugLog: @" Firestack"
7466 msg: @" Reloading firestack" ];
7567}
0 commit comments