[core][both] added delete app method (android is just a stub method as the firebase sdk does not support it)
This commit is contained in:
parent
e96c5db8d1
commit
03377255f6
|
@ -10,6 +10,7 @@ import java.util.HashMap;
|
|||
// react
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.bridge.LifecycleEventListener;
|
||||
|
@ -50,7 +51,7 @@ public class RNFirebaseModule extends ReactContextBaseJavaModule implements Life
|
|||
}
|
||||
|
||||
@ReactMethod
|
||||
public void initializeApp(String name, ReadableMap options, Callback callback) {
|
||||
public void initializeApp(String appName, ReadableMap options, Callback callback) {
|
||||
FirebaseOptions.Builder builder = new FirebaseOptions.Builder();
|
||||
|
||||
builder.setApplicationId(options.getString("appId"));
|
||||
|
@ -61,14 +62,28 @@ public class RNFirebaseModule extends ReactContextBaseJavaModule implements Life
|
|||
builder.setStorageBucket(options.getString("storageBucket"));
|
||||
// todo firebase sdk has no client id setter
|
||||
|
||||
FirebaseApp.initializeApp(getReactApplicationContext(), builder.build(), name);
|
||||
FirebaseApp.initializeApp(getReactApplicationContext(), builder.build(), appName);
|
||||
|
||||
// todo expand on callback result
|
||||
WritableMap response = Arguments.createMap();
|
||||
response.putString("result", "success");
|
||||
callback.invoke(null, response);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void deleteApp(String appName, Promise promise) {
|
||||
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
||||
|
||||
if (firebaseApp == null) {
|
||||
promise.resolve(null);
|
||||
} else {
|
||||
// todo ? not implemented on firebase sdk
|
||||
promise.reject(
|
||||
"app/delete-app-failed",
|
||||
"Failed to delete app. The android Firebase SDK currently does not support this functionality"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private WritableMap getPlayServicesStatus() {
|
||||
GoogleApiAvailability gapi = GoogleApiAvailability.getInstance();
|
||||
final int status = gapi.isGooglePlayServicesAvailable(getReactApplicationContext());
|
||||
|
@ -117,8 +132,8 @@ public class RNFirebaseModule extends ReactContextBaseJavaModule implements Life
|
|||
|
||||
appProps.put("name", appName);
|
||||
appProps.put("apiKey", appOptions.getApiKey());
|
||||
appProps.put("applicationId", appOptions.getApplicationId());
|
||||
appProps.put("databaseUrl", appOptions.getDatabaseUrl());
|
||||
appProps.put("appId", appOptions.getApplicationId());
|
||||
appProps.put("databaseURL", appOptions.getDatabaseUrl());
|
||||
appProps.put("messagingSenderId", appOptions.getGcmSenderId());
|
||||
appProps.put("projectId", appOptions.getProjectId());
|
||||
appProps.put("storageBucket", appOptions.getStorageBucket());
|
||||
|
|
|
@ -21,14 +21,14 @@ RCT_EXPORT_MODULE(RNFirebase);
|
|||
* @return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(initializeApp:
|
||||
(NSString *) name
|
||||
(NSString *) appName
|
||||
options:
|
||||
(NSDictionary *) options
|
||||
callback:
|
||||
(RCTResponseSenderBlock) callback) {
|
||||
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
FIRApp *existingApp = [FIRApp appNamed:name];
|
||||
FIRApp *existingApp = [FIRApp appNamed:appName];
|
||||
|
||||
if (!existingApp) {
|
||||
FIROptions *firOptions = [[FIROptions alloc] initWithGoogleAppID:[options valueForKey:@"appId"] GCMSenderID:[options valueForKey:@"messagingSenderId"]];
|
||||
|
@ -43,27 +43,57 @@ RCT_EXPORT_METHOD(initializeApp:
|
|||
firOptions.deepLinkURLScheme = [options valueForKey:@"deepLinkURLScheme"];
|
||||
firOptions.bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"];
|
||||
|
||||
[FIRApp configureWithName:name options:firOptions];
|
||||
[FIRApp configureWithName:appName options:firOptions];
|
||||
}
|
||||
|
||||
// todo expand on callback result
|
||||
callback(@[[NSNull null], @{@"result": @"success"}]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a firebase app
|
||||
* @return
|
||||
*/
|
||||
RCT_EXPORT_METHOD(deleteApp:
|
||||
(NSString *) appName
|
||||
resolver:
|
||||
(RCTPromiseResolveBlock) resolve
|
||||
rejecter:
|
||||
(RCTPromiseRejectBlock) reject) {
|
||||
|
||||
FIRApp *existingApp = [FIRApp appNamed:appName];
|
||||
|
||||
if (!existingApp) {
|
||||
return resolve([NSNull null]);
|
||||
}
|
||||
|
||||
[existingApp deleteApp:^(BOOL success) {
|
||||
if (success) {
|
||||
resolve([NSNull null]);
|
||||
} else {
|
||||
reject(@"app/delete-app-failed", @"Failed to delete the specified app.", nil);
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* React native constant exports - exports native firebase apps mainly
|
||||
* @return
|
||||
*/
|
||||
- (NSDictionary *)constantsToExport {
|
||||
NSMutableDictionary *constants = [NSMutableDictionary new];
|
||||
NSDictionary *firApps = [FIRApp allApps];
|
||||
NSMutableArray *appsArray = [NSMutableArray new];
|
||||
|
||||
for (id key in firApps) {
|
||||
NSMutableDictionary * appOptions = [NSMutableDictionary new];
|
||||
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[@"appId"] = firOptions.googleAppID;
|
||||
appOptions[@"databaseURL"] = firOptions.databaseURL;
|
||||
appOptions[@"messagingSenderId"] = firOptions.GCMSenderID;
|
||||
appOptions[@"projectId"] = firOptions.projectID;
|
||||
appOptions[@"storageBucket"] = firOptions.storageBucket;
|
||||
|
@ -75,7 +105,6 @@ RCT_EXPORT_METHOD(initializeApp:
|
|||
appOptions[@"deepLinkUrlScheme"] = firOptions.deepLinkURLScheme;
|
||||
|
||||
[appsArray addObject:appOptions];
|
||||
NSLog(@"test");
|
||||
}
|
||||
|
||||
constants[@"apps"] = appsArray;
|
||||
|
|
|
@ -22,6 +22,18 @@ export default class FirebaseApp {
|
|||
|
||||
// native ios/android to confirm initialized
|
||||
this._initialized = false;
|
||||
this._nativeInitialized = false;
|
||||
|
||||
// modules
|
||||
this.admob = this._staticsOrModuleInstance('admob', AdMobStatics, AdMob);
|
||||
this.auth = this._staticsOrModuleInstance('auth', AuthStatics, Auth);
|
||||
this.analytics = this._staticsOrModuleInstance('analytics', {}, Analytics);
|
||||
this.config = this._staticsOrModuleInstance('config', {}, RemoteConfig);
|
||||
this.crash = this._staticsOrModuleInstance('crash', {}, Crash);
|
||||
this.database = this._staticsOrModuleInstance('database', DatabaseStatics, Database);
|
||||
this.messaging = this._staticsOrModuleInstance('messaging', MessagingStatics, Messaging);
|
||||
this.perf = this._staticsOrModuleInstance('perf', {}, Performance);
|
||||
this.storage = this._staticsOrModuleInstance('storage', StorageStatics, Storage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,14 +43,13 @@ export default class FirebaseApp {
|
|||
*/
|
||||
_initializeApp(native = false) {
|
||||
if (native) {
|
||||
// for apps already initialized natively that we have info
|
||||
// from RN constants
|
||||
// for apps already initialized natively that
|
||||
// we have info from RN constants
|
||||
this._initialized = true;
|
||||
this._nativeInitialized = true;
|
||||
} else {
|
||||
FirebaseCoreModule.initializeApp(this._name, this._options, (error, result) => {
|
||||
this._initialized = true;
|
||||
this._nativeInitialized = false;
|
||||
INTERNALS.SharedEventEmitter.emit(`AppReady:${this._name}`, { error, result });
|
||||
});
|
||||
}
|
||||
|
@ -78,10 +89,14 @@ export default class FirebaseApp {
|
|||
);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
return FirebaseCoreModule.deleteApp(this._name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {*}
|
||||
*/
|
||||
onReady(): Promise {
|
||||
if (this._initialized) return Promise.resolve(this);
|
||||
|
||||
|
@ -93,47 +108,6 @@ export default class FirebaseApp {
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* MODULES
|
||||
*/
|
||||
|
||||
get admob() {
|
||||
return this._staticsOrModuleInstance('admob', AdMobStatics, AdMob);
|
||||
}
|
||||
|
||||
get auth() {
|
||||
return this._staticsOrModuleInstance('auth', AuthStatics, Auth);
|
||||
}
|
||||
|
||||
get analytics() {
|
||||
return this._staticsOrModuleInstance('analytics', {}, Analytics);
|
||||
}
|
||||
|
||||
get config() {
|
||||
return this._staticsOrModuleInstance('config', {}, RemoteConfig);
|
||||
}
|
||||
|
||||
get crash() {
|
||||
return this._staticsOrModuleInstance('crash', {}, Crash);
|
||||
}
|
||||
|
||||
get database() {
|
||||
return this._staticsOrModuleInstance('database', DatabaseStatics, Database);
|
||||
}
|
||||
|
||||
get messaging() {
|
||||
return this._staticsOrModuleInstance('messaging', MessagingStatics, Messaging);
|
||||
}
|
||||
|
||||
get perf() {
|
||||
return this._staticsOrModuleInstance('perf', {}, Performance);
|
||||
}
|
||||
|
||||
get storage() {
|
||||
return this._staticsOrModuleInstance('storage', StorageStatics, Storage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
|
|
Loading…
Reference in New Issue