@@ -42,6 +42,10 @@ + (void) initializeFirestack:(Firestack *) instance
42
42
43
43
_sharedInstance = instance;
44
44
45
+ [[NSNotificationCenter defaultCenter ]
46
+ postNotificationName: kFirestackInitialized
47
+ object: [instance getConfig ]];
48
+
45
49
[[NSNotificationCenter defaultCenter ] addObserver: self
46
50
selector: @selector (reloadFirestack )
47
51
name: RCTReloadNotification
@@ -81,166 +85,97 @@ - (FIRApp *) firebaseApp
81
85
RCT_EXPORT_METHOD (configureWithOptions:(NSDictionary *) opts
82
86
callback:(RCTResponseSenderBlock)callback)
83
87
{
84
- NSLog (@" dispatch once on configure" );
85
- dispatch_async (dispatch_get_main_queue (),^{
86
- // Are we debugging, yo?
87
- self.debug = [opts valueForKey: @" debug" ] != nil ? YES : NO ;
88
- NSLog (@" options passed into configureWithOptions: %@ " , [opts valueForKey: @" debug" ]);
89
-
88
+ // Are we debugging, yo?
89
+ self.debug = [opts valueForKey: @" debug" ] != nil ? YES : NO ;
90
+ NSDictionary *props = [self pluckOptions: opts];
91
+
92
+ @try {
93
+ if (self.debug ) {
94
+ NSLog (@" debugging: %@ " , [props valueForKey: @" debug" ]);
95
+ NSLog (@" cloudMessaging: %@ " , [props valueForKey: @" cloudMessaging" ]);
96
+ }
97
+
98
+ NSLog (@" Configuring firestack instance: %@ " , self);
99
+ // Save configuration option
100
+ NSDictionary *cfg = [self getConfig ];
101
+ [cfg setValuesForKeysWithDictionary: props];
102
+ self.configuration = cfg;
103
+
104
+ [Firestack initializeFirestack: self ];
105
+ self.configured = YES ;
106
+ callback (@[[NSNull null ], props]);
107
+ }
108
+ @catch (NSException *exception) {
109
+ NSLog (@" Exception occurred while configuring: %@ " , exception);
110
+ [self debugLog: @" Configuring error"
111
+ msg: [NSString stringWithFormat: @" An error occurred while configuring: %@ " , [exception debugDescription ]]];
112
+ NSDictionary *errProps = @{
113
+ @" error" : [exception name ],
114
+ @" description" : [exception debugDescription ]
115
+ };
116
+ callback (@[errProps]);
117
+ }
118
+ }
119
+
120
+ /* *
121
+ * Pluck the options that are given by JS
122
+ **/
123
+ - (NSDictionary *) pluckOptions : (NSDictionary *) opts
124
+ {
90
125
NSDictionary *keyMapping = @{
91
- @" GOOGLE_APP_ID" : @[
92
- @" appId" ,
93
- @" googleAppId" ,
94
- @" applicationId"
95
- ],
96
- @" BUNDLE_ID" : @[
97
- @" bundleId" ,
98
- @" bundleID"
99
- ],
100
- @" GCM_SENDER_ID" : @[
101
- @" gcmSenderID" ,
102
- @" GCMSenderID"
103
- ],
104
- @" API_KEY" : @[
105
- @" apiKey"
106
- ],
107
- @" CLIENT_ID" : @[
108
- @" clientId" ,
109
- @" clientID"
110
- ],
111
- @" TRACKING_ID" : @[
112
- @" trackingID" ,
113
- @" trackingId"
114
- ],
115
- @" ANDROID_CLIENT_ID" : @[
116
- @" applicationId" ,
117
- @" clientId" ,
118
- @" clientID" ,
119
- @" androidClientID" ,
120
- @" androidClientId"
121
- ],
122
- @" DATABASE_URL" : @[
123
- @" databaseUrl" ,
124
- @" databaseURL"
125
- ],
126
- @" STORAGE_BUCKET" : @[
127
- @" storageBucket"
128
- ],
129
- @" PROJECT_ID" : @[
130
- @" projectId" ,
131
- @" projectID"
132
- ],
133
- @" TRACKING_ID" : @[
134
- @" trackingID" ,
135
- @" trackingId"
136
- ],
137
- @" DEEP_LINK_SCHEME" : @[
138
- @" deepLinkScheme"
139
- ],
140
- @" MESSAGING_SENDER_ID" : @[
141
- @" messagingSenderId" ,
142
- @" messagingSenderID"
143
- ]
144
- };
145
- NSArray *optionKeys = [keyMapping allKeys ];
146
-
147
- NSMutableDictionary *props;
148
-
149
- NSString *plistPath = [[NSBundle mainBundle ] pathForResource: @" GoogleService-Info" ofType: @" plist" ];
150
-
151
- if ([[NSFileManager defaultManager ] fileExistsAtPath: plistPath]) {
152
- // If the Firebase plist is included
153
- props = [NSMutableDictionary dictionaryWithContentsOfFile: plistPath];
154
- } else {
155
- props = [[NSMutableDictionary alloc ] initWithCapacity: [optionKeys count ]];
126
+ @" cloudMessaging" : @[
127
+ @" messaging" ,
128
+ ]
129
+ };
130
+ NSArray *optionKeys = [keyMapping allKeys ];
131
+ NSString *plistPath = [[NSBundle mainBundle ] pathForResource: @" Info" ofType: @" plist" ];
132
+
133
+ NSDictionary *defaultOptions = @{
134
+ @" debug" : @NO ,
135
+ @" cloudMessaging" : @{
136
+ @" enabled" : @YES
156
137
}
157
-
158
- // Bundle ID either from options OR from the main bundle
159
- NSString *bundleID;
160
- if ([opts valueForKey: @" bundleID" ]) {
161
- bundleID = [opts valueForKey: @" bundleID" ];
162
- } else {
163
- bundleID = [[NSBundle mainBundle ] bundleIdentifier ];
138
+ };
139
+
140
+ NSMutableDictionary *props = [defaultOptions copy ];
141
+
142
+ if ([[NSFileManager defaultManager ] fileExistsAtPath: plistPath]) {
143
+ // If the Info plist is included
144
+ NSDictionary *infoProps = [NSMutableDictionary dictionaryWithContentsOfFile: plistPath];
145
+ NSDictionary *firestackOptions = [infoProps valueForKey: @" firestack" ];
146
+ if (firestackOptions != nil ) {
147
+ props = [firestackOptions copy ];
164
148
}
165
- [props setValue: bundleID forKey: @" BUNDLE_ID" ];
166
-
167
- // Prefer the user configuration options over the default options
168
- for (int i=0 ; i < [optionKeys count ]; i++) {
169
- // Traditional for loop here
170
- @try {
171
- NSString *key = [optionKeys objectAtIndex: i];
172
- // If the name is capitalized
173
- if ([opts valueForKey: key] != nil ) {
174
- NSString *value = [opts valueForKey: key];
149
+ }
150
+
151
+ // Prefer the user configuration options over the default options
152
+ for (int i=0 ; i < [optionKeys count ]; i++) {
153
+ // Traditional for loop here
154
+ @try {
155
+ NSString *key = [optionKeys objectAtIndex: i];
156
+
157
+ // If the name is the key name
158
+ NSMutableArray *possibleNames = [NSMutableArray arrayWithArray: [keyMapping objectForKey: key]];
159
+ [possibleNames addObject: key];
160
+
161
+ for (NSString *name in possibleNames) {
162
+ if ([opts valueForKey: name] != nil ) {
163
+ // The user passed this option in
164
+ NSString *value = [opts valueForKey: name];
175
165
[props setValue: value forKey: key];
176
166
}
177
-
178
- NSArray *possibleNames = [keyMapping objectForKey: key];
179
-
180
- for (NSString *name in possibleNames) {
181
- if ([opts valueForKey: name] != nil ) {
182
- // The user passed this option in
183
- NSString *value = [opts valueForKey: name];
184
- [props setValue: value forKey: key];
185
- }
186
- }
187
- }
188
- @catch (NSException *err) {
189
- // Uh oh?
190
- NSLog (@" An error occurred: %@ " , err);
191
167
}
192
168
}
193
-
194
- @try {
195
- if (self.debug ) {
196
- NSLog (@" props ->: %@ " , props);
197
- NSLog (@" GOOGLE_APP_ID: %@ " , [props valueForKey: @" GOOGLE_APP_ID" ]);
198
- NSLog (@" BUNDLE_ID: %@ " , [props valueForKey: @" BUNDLE_ID" ]);
199
- NSLog (@" GCM_SENDER_ID: %@ " , [props valueForKey: @" GCM_SENDER_ID" ]);
200
- NSLog (@" API_KEY: %@ " , [props valueForKey: @" API_KEY" ]);
201
- NSLog (@" CLIENT_ID: %@ " , [props valueForKey: @" CLIENT_ID" ]);
202
- NSLog (@" TRACKING_ID: %@ " , [props valueForKey: @" TRACKING_ID" ]);
203
- NSLog (@" ANDROID_CLIENT_ID: %@ " , [props valueForKey: @" ANDROID_CLIENT_ID" ]);
204
- NSLog (@" DATABASE_URL: %@ " , [props valueForKey: @" DATABASE_URL" ]);
205
- NSLog (@" STORAGE_BUCKET: %@ " , [props valueForKey: @" STORAGE_BUCKET" ]);
206
- NSLog (@" DEEP_LINK_SCHEME: %@ " , [props valueForKey: @" DEEP_LINK_SCHEME" ]);
207
- }
208
-
209
- FIROptions *finalOptions = [[FIROptions alloc ]
210
- initWithGoogleAppID: [props valueForKey: @" GOOGLE_APP_ID" ]
211
- bundleID: [props valueForKey: @" BUNDLE_ID" ]
212
- GCMSenderID: [props valueForKey: @" GCM_SENDER_ID" ]
213
- APIKey: [props valueForKey: @" API_KEY" ]
214
- clientID: [props valueForKey: @" CLIENT_ID" ]
215
- trackingID: [props valueForKey: @" TRACKING_ID" ]
216
- androidClientID: [props valueForKey: @" ANDROID_CLIENT_ID" ]
217
- databaseURL: [props valueForKey: @" DATABASE_URL" ]
218
- storageBucket: [props valueForKey: @" STORAGE_BUCKET" ]
219
- deepLinkURLScheme: [props valueForKey: @" DEEP_LINK_SCHEME" ]];
220
-
221
- NSLog (@" Configuring firestack instance: %@ " , self);
222
- // Save configuration option
223
- // NSDictionary *cfg = [self getConfig];
224
- // [cfg setValuesForKeysWithDictionary:props];
225
- // self.configuration = cfg;
226
-
227
- [Firestack initializeFirestack: self ];
228
- self.configured = YES ;
229
- callback (@[[NSNull null ], props]);
230
- }
231
- @catch (NSException *exception) {
232
- NSLog (@" Exception occurred while configuring: %@ " , exception);
233
- [self debugLog: @" Configuring error"
234
- msg: [NSString stringWithFormat: @" An error occurred while configuring: %@ " , [exception debugDescription ]]];
235
- NSDictionary *errProps = @{
236
- @" error" : [exception name ],
237
- @" description" : [exception debugDescription ]
238
- };
239
- callback (@[errProps]);
169
+ @catch (NSException *err) {
170
+ // Uh oh?
171
+ NSLog (@" An error occurred: %@ " , err);
240
172
}
241
- });
173
+ }
174
+
175
+ return props;
242
176
}
243
177
178
+
244
179
RCT_EXPORT_METHOD (configure:(RCTResponseSenderBlock)callback)
245
180
{
246
181
NSDictionary *props = @{};
0 commit comments