2017-03-09 15:26:28 +00:00
|
|
|
#import "RNFirebase.h"
|
2017-06-29 16:24:34 +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:
|
|
|
|
(NSString *) name
|
|
|
|
options:
|
|
|
|
(NSDictionary *) options
|
|
|
|
callback:
|
|
|
|
(RCTResponseSenderBlock) callback) {
|
|
|
|
|
|
|
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
|
|
FIRApp *existingApp = [FIRApp appNamed:name];
|
|
|
|
|
|
|
|
if (!existingApp) {
|
2017-07-17 17:20:27 +00:00
|
|
|
FIROptions *firOptions = [[FIROptions alloc] initWithGoogleAppID:[options valueForKey:@"iosAppId"] GCMSenderID:[options valueForKey:@"messagingSenderId"]];
|
2017-06-29 16:24:34 +00:00
|
|
|
|
|
|
|
firOptions.APIKey = [options valueForKey:@"apiKey"];
|
|
|
|
firOptions.projectID = [options valueForKey:@"projectId"];
|
|
|
|
firOptions.clientID = [options valueForKey:@"iosClientId"];
|
|
|
|
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"];
|
|
|
|
|
|
|
|
[FIRApp configureWithName:name options:firOptions];
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo expand on callback result
|
|
|
|
callback(@[[NSNull null], @{@"result": @"success"}]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-31 08:54:02 +00:00
|
|
|
@end
|