2017-03-09 15:26:28 +00:00
|
|
|
#import "RNFirebase.h"
|
2018-01-03 20:00:38 +00:00
|
|
|
#import "RNFirebaseUtil.h"
|
2017-08-17 16:25:51 +00:00
|
|
|
#import <FirebaseCore/FirebaseCore.h>
|
2017-03-09 15:26:28 +00:00
|
|
|
|
|
|
|
@implementation RNFirebase
|
2017-05-25 14:01:53 +00:00
|
|
|
RCT_EXPORT_MODULE(RNFirebase);
|
2017-03-09 15:26:28 +00:00
|
|
|
|
2017-05-25 14:01:53 +00:00
|
|
|
- (id)init {
|
2017-03-09 15:26:28 +00:00
|
|
|
self = [super init];
|
|
|
|
if (self != nil) {
|
|
|
|
NSLog(@"Setting up RNFirebase instance");
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray<NSString *> *)supportedEvents {
|
2017-05-31 08:54:02 +00:00
|
|
|
return @[];
|
2017-03-09 15:26:28 +00:00
|
|
|
}
|
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
/**
|
|
|
|
* Initialize a new firebase app instance or ignore if currently exists.
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
RCT_EXPORT_METHOD(initializeApp:
|
2018-01-03 20:00:38 +00:00
|
|
|
(NSString *) appDisplayName
|
2017-06-29 16:24:34 +00:00
|
|
|
options:
|
|
|
|
(NSDictionary *) options
|
|
|
|
callback:
|
|
|
|
(RCTResponseSenderBlock) callback) {
|
|
|
|
|
|
|
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
2018-01-03 20:00:38 +00:00
|
|
|
FIRApp *existingApp = [RNFirebaseUtil getApp:appDisplayName];
|
2017-06-29 16:24:34 +00:00
|
|
|
|
|
|
|
if (!existingApp) {
|
2017-07-17 18:43:36 +00:00
|
|
|
FIROptions *firOptions = [[FIROptions alloc] initWithGoogleAppID:[options valueForKey:@"appId"] GCMSenderID:[options valueForKey:@"messagingSenderId"]];
|
2017-06-29 16:24:34 +00:00
|
|
|
|
|
|
|
firOptions.APIKey = [options valueForKey:@"apiKey"];
|
|
|
|
firOptions.projectID = [options valueForKey:@"projectId"];
|
2017-07-17 18:43:36 +00:00
|
|
|
firOptions.clientID = [options valueForKey:@"clientId"];
|
2017-06-29 16:24:34 +00:00
|
|
|
firOptions.trackingID = [options valueForKey:@"trackingId"];
|
|
|
|
firOptions.databaseURL = [options valueForKey:@"databaseURL"];
|
|
|
|
firOptions.storageBucket = [options valueForKey:@"storageBucket"];
|
|
|
|
firOptions.androidClientID = [options valueForKey:@"androidClientId"];
|
|
|
|
firOptions.deepLinkURLScheme = [options valueForKey:@"deepLinkURLScheme"];
|
|
|
|
firOptions.bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"];
|
|
|
|
|
2018-01-03 20:00:38 +00:00
|
|
|
NSString *appName = [RNFirebaseUtil getAppName:appDisplayName];
|
2017-07-18 05:02:53 +00:00
|
|
|
[FIRApp configureWithName:appName options:firOptions];
|
2017-06-29 16:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(@[[NSNull null], @{@"result": @"success"}]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-18 05:02:53 +00:00
|
|
|
/**
|
|
|
|
* Delete a firebase app
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
RCT_EXPORT_METHOD(deleteApp:
|
2018-01-03 20:00:38 +00:00
|
|
|
(NSString *) appDisplayName
|
2017-07-18 05:02:53 +00:00
|
|
|
resolver:
|
|
|
|
(RCTPromiseResolveBlock) resolve
|
|
|
|
rejecter:
|
|
|
|
(RCTPromiseRejectBlock) reject) {
|
|
|
|
|
2018-01-03 20:00:38 +00:00
|
|
|
FIRApp *existingApp = [RNFirebaseUtil getApp:appDisplayName];
|
2017-07-18 05:02:53 +00:00
|
|
|
|
|
|
|
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
|
2017-10-03 09:03:41 +00:00
|
|
|
* @return NSDictionary
|
2017-07-18 05:02:53 +00:00
|
|
|
*/
|
2017-07-17 17:20:27 +00:00
|
|
|
- (NSDictionary *)constantsToExport {
|
|
|
|
NSMutableDictionary *constants = [NSMutableDictionary new];
|
|
|
|
NSDictionary *firApps = [FIRApp allApps];
|
|
|
|
NSMutableArray *appsArray = [NSMutableArray new];
|
|
|
|
|
|
|
|
for (id key in firApps) {
|
2017-07-18 05:02:53 +00:00
|
|
|
NSMutableDictionary *appOptions = [NSMutableDictionary new];
|
2017-07-17 17:20:27 +00:00
|
|
|
FIRApp *firApp = firApps[key];
|
|
|
|
FIROptions *firOptions = [firApp options];
|
2018-01-03 20:00:38 +00:00
|
|
|
appOptions[@"name"] = [RNFirebaseUtil getAppDisplayName:firApp.name];
|
2017-07-17 17:20:27 +00:00
|
|
|
appOptions[@"apiKey"] = firOptions.APIKey;
|
2017-07-18 05:02:53 +00:00
|
|
|
appOptions[@"appId"] = firOptions.googleAppID;
|
|
|
|
appOptions[@"databaseURL"] = firOptions.databaseURL;
|
2017-07-17 17:20:27 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
constants[@"apps"] = appsArray;
|
|
|
|
return constants;
|
|
|
|
}
|
|
|
|
|
2017-10-12 08:18:01 +00:00
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2017-07-17 17:20:27 +00:00
|
|
|
|
2017-05-31 08:54:02 +00:00
|
|
|
@end
|