1313
1414@implementation Firestack
1515
16+ - (void )dealloc
17+ {
18+ NSLog (@" Dealloc called on Firestack" );
19+ [[FIRApp defaultApp ] deleteApp: ^(BOOL success) {
20+ if (success) {
21+ NSLog (@" Successfully removed app" );
22+ } else {
23+ NSLog (@" Unsuccessfully cleaned up all" );
24+ }
25+ }];
26+ }
27+
1628typedef void (^UserWithTokenResponse)(NSDictionary *, NSError *);
1729
1830RCT_EXPORT_MODULE (Firestack);
1931
2032RCT_EXPORT_METHOD (configureWithOptions:(NSDictionary *) opts
2133 callback:(RCTResponseSenderBlock)callback)
2234{
23-
2435 // Are we debugging, yo?
2536 self.debug = [opts valueForKey: @" debug" ] != nil ? YES : NO ;
37+ NSLog (@" options passed into configureWithOptions: %@ " , [opts valueForKey: @" debug" ]);
38+
39+ NSDictionary *keyMapping = @{
40+ @" GOOGLE_APP_ID" : @[
41+ @" appId" ,
42+ @" googleAppId" ,
43+ @" applicationId"
44+ ],
45+ @" BUNDLE_ID" : @[
46+ @" bundleId" ,
47+ @" bundleID"
48+ ],
49+ @" GCM_SENDER_ID" : @[
50+ @" gcmSenderID" ,
51+ @" GCMSenderID"
52+ ],
53+ @" API_KEY" : @[
54+ @" apiKey"
55+ ],
56+ @" CLIENT_ID" : @[
57+ @" clientId" ,
58+ @" clientID"
59+ ],
60+ @" TRACKING_ID" : @[
61+ @" trackingID" ,
62+ @" trackingId"
63+ ],
64+ @" ANDROID_CLIENT_ID" : @[
65+ @" applicationId" ,
66+ @" clientId" ,
67+ @" clientID" ,
68+ @" androidClientID" ,
69+ @" androidClientId"
70+ ],
71+ @" DATABASE_URL" : @[
72+ @" databaseUrl" ,
73+ @" databaseURL"
74+ ],
75+ @" STORAGE_BUCKET" : @[
76+ @" storageBucket"
77+ ],
78+ @" PROJECT_ID" : @[
79+ @" projectId" ,
80+ @" projectID"
81+ ],
82+ @" TRACKING_ID" : @[
83+ @" trackingID" ,
84+ @" trackingId"
85+ ],
86+ @" DEEP_LINK_SCHEME" : @[
87+ @" deepLinkScheme"
88+ ]
89+ };
90+ NSArray *optionKeys = [keyMapping allKeys ];
2691
27- FIROptions *firestackOptions = [FIROptions defaultOptions ];
92+ NSMutableDictionary *props;
93+
94+ NSString *plistPath = [[NSBundle mainBundle ] pathForResource: @" GoogleService-Info" ofType: @" plist" ];
95+
96+ if ([[NSFileManager defaultManager ] fileExistsAtPath: plistPath]) {
97+ // If the Firebase plist is included
98+ props = [NSMutableDictionary dictionaryWithContentsOfFile: plistPath];
99+ } else {
100+ props = [[NSMutableDictionary alloc ] initWithCapacity: [optionKeys count ]];
101+ }
102+
28103 // Bundle ID either from options OR from the main bundle
29104 NSString *bundleID;
30105 if ([opts valueForKey: @" bundleID" ]) {
31106 bundleID = [opts valueForKey: @" bundleID" ];
32107 } else {
33108 bundleID = [[NSBundle mainBundle ] bundleIdentifier ];
34109 }
110+ [props setValue: bundleID forKey: @" BUNDLE_ID" ];
35111
36112 // Prefer the user configuration options over the default options
37- NSArray *keyOptions = @[@" APIKey" , @" clientID" , @" trackingID" ,
38- @" GCMSenderID" , @" androidClientID" ,
39- @" googleAppID" , @" databaseURL" ,
40- @" deepLinkURLScheme" , @" storageBucket" ];
41-
42- NSMutableDictionary *props = [[NSMutableDictionary alloc ] initWithCapacity: [keyOptions count ]];
43- for (int i=0 ; i < [keyOptions count ]; i++) {
113+ for (int i=0 ; i < [optionKeys count ]; i++) {
44114 // Traditional for loop here
45115 @try {
46- NSString *key = [keyOptions objectAtIndex: i];
47- NSString *value = [opts valueForKey: key];
48- if (value != nil ) {
49- [props setObject: value forKey: key];
50- } else if ([firestackOptions valueForKey: key] != nil ) {
51- [props setObject: [firestackOptions valueForKey: key] forKey: key];
116+ NSString *key = [optionKeys objectAtIndex: i];
117+ // If the name is capitalized
118+ if ([opts valueForKey: key] != nil ) {
119+ NSString *value = [opts valueForKey: key];
120+ [props setValue: value forKey: key];
121+ }
122+
123+ NSArray *possibleNames = [keyMapping objectForKey: key];
124+
125+ for (NSString *name in possibleNames) {
126+ if ([opts valueForKey: name] != nil ) {
127+ // The user passed this option in
128+ NSString *value = [opts valueForKey: name];
129+ [props setValue: value forKey: key];
130+ }
52131 }
53132 }
54133 @catch (NSException *err) {
@@ -57,51 +136,40 @@ @implementation Firestack
57136 }
58137 }
59138
60- // If the apiKey is lowercase
61- if ([opts valueForKey: @" apiKey" ]) {
62- [props setValue: [opts valueForKey: @" apiKey" ] forKey: @" APIKey" ];
63- }
64-
65- // if the app id is lowercase
66- if ([opts valueForKey: @" googleAppId" ]) {
67- [props setValue: [opts valueForKey: @" googleAppId" ] forKey: @" googleAppID" ];
68- } else if ([opts valueForKey: @" appId" ]) {
69- [props setValue: [opts valueForKey: @" appId" ] forKey: @" googleAppID" ];
70- }
71-
72- // If we have an app id but no tracking id
73- if (![opts valueForKey: @" trackingID" ] && [opts valueForKey: @" googleAppID" ]) {
74- [props setValue: [opts valueForKey: @" googleAppID" ] forKey: @" trackingID" ];
75- }
76-
77- if (![opts valueForKey: @" androidClientID" ] && [opts valueForKey: @" clientID" ]) {
78- [props setValue: [opts valueForKey: @" clientID" ] forKey: @" androidClientID" ];
79- }
80-
81139 @try {
82- FIROptions *finalOptions = [[FIROptions alloc ]
83- initWithGoogleAppID: [props valueForKey: @" googleAppID" ]
84- bundleID: bundleID
85- GCMSenderID: [props valueForKey: @" GCMSenderID" ]
86- APIKey: [props valueForKey: @" APIKey" ]
87- clientID: [props valueForKey: @" clientID" ]
88- trackingID: [props valueForKey: @" trackingID" ]
89- androidClientID: [props valueForKey: @" androidClientID" ]
90- databaseURL: [props valueForKey: @" databaseURL" ]
91- storageBucket: [props valueForKey: @" storageBucket" ]
92- deepLinkURLScheme: [props valueForKey: @" deepLinkURLScheme" ]];
93-
94- for (NSString *key in props) {
95- [self debugLog: key msg: [finalOptions valueForKey: key]];
140+ if (self.debug ) {
141+ NSLog (@" props ->: %@ " , props);
142+ NSLog (@" GOOGLE_APP_ID: %@ " , [props valueForKey: @" GOOGLE_APP_ID" ]);
143+ NSLog (@" BUNDLE_ID: %@ " , [props valueForKey: @" BUNDLE_ID" ]);
144+ NSLog (@" GCM_SENDER_ID: %@ " , [props valueForKey: @" GCM_SENDER_ID" ]);
145+ NSLog (@" API_KEY: %@ " , [props valueForKey: @" API_KEY" ]);
146+ NSLog (@" CLIENT_ID: %@ " , [props valueForKey: @" CLIENT_ID" ]);
147+ NSLog (@" TRACKING_ID: %@ " , [props valueForKey: @" TRACKING_ID" ]);
148+ NSLog (@" ANDROID_CLIENT_ID: %@ " , [props valueForKey: @" ANDROID_CLIENT_ID" ]);
149+ NSLog (@" DATABASE_URL: %@ " , [props valueForKey: @" DATABASE_URL" ]);
150+ NSLog (@" STORAGE_BUCKET: %@ " , [props valueForKey: @" STORAGE_BUCKET" ]);
151+ NSLog (@" DEEP_LINK_SCHEME: %@ " , [props valueForKey: @" DEEP_LINK_SCHEME" ]);
96152 }
97- [self debugLog: @" bundleID" msg: bundleID];
153+
154+ FIROptions *finalOptions = [[FIROptions alloc ]
155+ initWithGoogleAppID: [props valueForKey: @" GOOGLE_APP_ID" ]
156+ bundleID: [props valueForKey: @" BUNDLE_ID" ]
157+ GCMSenderID: [props valueForKey: @" GCM_SENDER_ID" ]
158+ APIKey: [props valueForKey: @" API_KEY" ]
159+ clientID: [props valueForKey: @" CLIENT_ID" ]
160+ trackingID: [props valueForKey: @" TRACKING_ID" ]
161+ androidClientID: [props valueForKey: @" ANDROID_CLIENT_ID" ]
162+ databaseURL: [props valueForKey: @" DATABASE_URL" ]
163+ storageBucket: [props valueForKey: @" STORAGE_BUCKET" ]
164+ deepLinkURLScheme: [props valueForKey: @" DEEP_LINK_SCHEME" ]];
98165
99166 // Save configuration option
100- NSDictionary *cfg = [self getConfig ];
101- [cfg setValuesForKeysWithDictionary: props];
167+ // NSDictionary *cfg = [self getConfig];
168+ // [cfg setValuesForKeysWithDictionary:props];
102169
103170 // if (!self.configured) {
104- [FIRApp configureWithOptions: finalOptions];
171+ [FIRApp configureWithOptions: finalOptions];
172+
105173 // self->_configured = YES;
106174 // }
107175 callback (@[[NSNull null ]]);
@@ -240,6 +308,7 @@ - (void) debugLog:(NSString *)title
240308 msg : (NSString *)msg
241309{
242310 if (self.debug ) {
311+ NSLog (@" %@ : %@ " , title, msg);
243312// [self sendJSEvent:DEBUG_EVENT
244313// props:@{
245314// @"name": title,
0 commit comments