@@ -234,6 +234,17 @@ export class FirebaseApp {
234234 }
235235}
236236
237+ const launchQueue = [ ] ;
238+
239+ declare const TNSFirebaseCore ;
240+
241+ const launchCallback = ( ) => {
242+ launchQueue . forEach ( ( item ) => item ( ) ) ;
243+ launchQueue . splice ( 0 ) ;
244+ } ;
245+
246+ TNSFirebaseCore . setOnAppFinishLaunchingCallback ( launchCallback ) ;
247+
237248export class Firebase {
238249 constructor ( ) {
239250 if ( firebaseInstance ) {
@@ -352,36 +363,32 @@ export class Firebase {
352363 }
353364 resolve ( fbApp ) ;
354365 } catch ( e ) {
355- reject ( new FirebaseError ( e . message ) )
366+ reject ( new FirebaseError ( e . message ) ) ;
356367 }
357- }
368+ } ;
358369
359370 if ( ! UIApplication . sharedApplication ) {
360- Application . ios . addNotificationObserver (
361- UIApplicationDidFinishLaunchingNotification ,
362- ( notification ) => {
363- initApp ( ) ;
364- }
365- )
371+ launchQueue . push ( ( ) => {
372+ initApp ( ) ;
373+ } ) ;
366374 } else {
367375 initApp ( ) ;
368376 }
369- } )
377+ } ) ;
370378 }
371379
372380 initializeAppWithPath ( path : string , options : FirebaseOptions = null , config ?: FirebaseConfig ) {
373381 return new Promise ( ( resolve , reject ) => {
374382 const initApp = ( ) => {
375383 try {
376384 if ( path . startsWith ( 'res://' ) ) {
377- path = NSBundle . mainBundle . pathForResourceOfType ( path . replace ( 'res://' , '' ) . replace ( '.plist' , '' ) , 'plist' )
385+ path = NSBundle . mainBundle . pathForResourceOfType ( path . replace ( 'res://' , '' ) . replace ( '.plist' , '' ) , 'plist' ) ;
378386 } else if ( path . startsWith ( '~/' ) ) {
379387 path = knownFolders . currentApp ( ) . path + '/' + path . replace ( '~/' , '' ) ;
380388 }
381389
382390 const nativeOptions = FIROptions . alloc ( ) . initWithContentsOfFile ( path ) ;
383391
384-
385392 if ( options ?. apiKey ) {
386393 nativeOptions . APIKey = options . apiKey ;
387394 }
@@ -430,7 +437,6 @@ export class Firebase {
430437 nativeOptions . trackingID = options . trackingId ;
431438 }
432439
433-
434440 FIRApp . configureWithOptions ( nativeOptions ) ;
435441
436442 const app = FIRApp . defaultApp ( ) ;
@@ -445,20 +451,17 @@ export class Firebase {
445451 }
446452 resolve ( fbApp ) ;
447453 } catch ( e ) {
448- reject ( new FirebaseError ( e . message ) )
454+ reject ( new FirebaseError ( e . message ) ) ;
449455 }
450- }
456+ } ;
451457 if ( ! UIApplication . sharedApplication ) {
452- Application . ios . addNotificationObserver (
453- UIApplicationDidFinishLaunchingNotification ,
454- ( notification ) => {
455- initApp ( ) ;
456- }
457- )
458+ launchQueue . push ( ( ) => {
459+ initApp ( ) ;
460+ } ) ;
458461 } else {
459462 initApp ( ) ;
460463 }
461- } )
464+ } ) ;
462465 }
463466}
464467
0 commit comments