[ios][app] apps initialized natively now automatically initialized js side - via react module getConstants
This commit is contained in:
parent
9a3e22431b
commit
813b91f5ad
|
@ -31,11 +31,7 @@ RCT_EXPORT_METHOD(initializeApp:
|
|||
FIRApp *existingApp = [FIRApp appNamed:name];
|
||||
|
||||
if (!existingApp) {
|
||||
FIROptions *firOptions = [
|
||||
[FIROptions alloc]
|
||||
initWithGoogleAppID:[options valueForKey:@"iosAppId"]
|
||||
GCMSenderID:[options valueForKey:@"messagingSenderId"]
|
||||
];
|
||||
FIROptions *firOptions = [[FIROptions alloc] initWithGoogleAppID:[options valueForKey:@"iosAppId"] GCMSenderID:[options valueForKey:@"messagingSenderId"]];
|
||||
|
||||
firOptions.APIKey = [options valueForKey:@"apiKey"];
|
||||
firOptions.projectID = [options valueForKey:@"projectId"];
|
||||
|
@ -55,4 +51,36 @@ RCT_EXPORT_METHOD(initializeApp:
|
|||
});
|
||||
}
|
||||
|
||||
- (NSDictionary *)constantsToExport {
|
||||
NSMutableDictionary *constants = [NSMutableDictionary new];
|
||||
NSDictionary *firApps = [FIRApp allApps];
|
||||
NSMutableArray *appsArray = [NSMutableArray new];
|
||||
|
||||
for (id key in firApps) {
|
||||
NSMutableDictionary * appOptions = [NSMutableDictionary new];
|
||||
FIRApp *firApp = firApps[key];
|
||||
FIROptions *firOptions = [firApp options];
|
||||
appOptions[@"name"] = firApp.name;
|
||||
appOptions[@"apiKey"] = firOptions.APIKey;
|
||||
appOptions[@"applicationId"] = firOptions.googleAppID;
|
||||
appOptions[@"databaseUrl"] = firOptions.databaseURL;
|
||||
appOptions[@"messagingSenderId"] = firOptions.GCMSenderID;
|
||||
appOptions[@"projectId"] = firOptions.projectID;
|
||||
appOptions[@"storageBucket"] = firOptions.storageBucket;
|
||||
|
||||
// missing from android sdk / ios only:
|
||||
appOptions[@"clientId"] = firOptions.clientID;
|
||||
appOptions[@"trackingId"] = firOptions.trackingID;
|
||||
appOptions[@"androidClientID"] = firOptions.androidClientID;
|
||||
appOptions[@"deepLinkUrlScheme"] = firOptions.deepLinkURLScheme;
|
||||
|
||||
[appsArray addObject:appOptions];
|
||||
NSLog(@"test");
|
||||
}
|
||||
|
||||
constants[@"apps"] = appsArray;
|
||||
return constants;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -21,22 +21,33 @@ export default class FirebaseApp {
|
|||
this._options = Object.assign({}, options);
|
||||
|
||||
// native ios/android to confirm initialized
|
||||
this._intialized = false;
|
||||
this._initialized = false;
|
||||
}
|
||||
|
||||
_initializeApp(local = false) {
|
||||
if (local) {
|
||||
/**
|
||||
*
|
||||
* @param native
|
||||
* @private
|
||||
*/
|
||||
_initializeApp(native = false) {
|
||||
if (native) {
|
||||
// for apps already initialized natively that we have info
|
||||
// from RN constants.
|
||||
// from RN constants
|
||||
this._initialized = true;
|
||||
this._nativeInitialized = true;
|
||||
} else {
|
||||
FirebaseCoreModule.initializeApp(this._name, this._options, (error, result) => {
|
||||
// todo check error/result
|
||||
this._initialized = true;
|
||||
this._nativeInitialized = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
get name() {
|
||||
if (this._name === INTERNALS.STRINGS.DEFAULT_APP_NAME) {
|
||||
// ios and android firebase sdk's return different
|
||||
|
@ -48,12 +59,25 @@ export default class FirebaseApp {
|
|||
return this._name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
get options() {
|
||||
return Object.assign({}, this._options);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {Promise}
|
||||
*/
|
||||
delete() {
|
||||
// todo
|
||||
if (this._name === INTERNALS.STRINGS.DEFAULT_APP_NAME && this._nativeInitialized) {
|
||||
return Promise.reject(
|
||||
new Error('Unable to delete the default native firebase app instance.'),
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ export default {
|
|||
* @return {string}
|
||||
*/
|
||||
ERROR_APP_NOT_INIT(appName) {
|
||||
return `The [${{ appName }}] firebase app has not been initialized!`;
|
||||
return `The [${appName}] firebase app has not been initialized!`;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue