@@ -281,6 +281,21 @@ - (NSString *)projectIDForAppAtIndex:(int)index {
281
281
return @" [none]" ;
282
282
}
283
283
284
+ /* * @fn googleAppIDForAppAtIndex:
285
+ @brief Returns the Google App ID for the Firebase app at the given index.
286
+ @param index The index for the app in the app manager.
287
+ @return The Google App ID of the project.
288
+ */
289
+ - (NSString *)googleAppIDForAppAtIndex : (int )index {
290
+ NSString *APIKey = [[AppManager sharedInstance ] appAtIndex: index ].options .APIKey ;
291
+ for (FIROptions *options in gFirebaseAppOptions ) {
292
+ if ([options.APIKey isEqualToString: APIKey]) {
293
+ return options.googleAppID ;
294
+ }
295
+ }
296
+ return @" [none]" ;
297
+ }
298
+
284
299
/* * @fn toggleProjectForAppAtIndex:
285
300
@brief Toggles the Firebase project for the Firebase app at the given index by recreating the
286
301
FIRApp instance with different options.
@@ -295,10 +310,19 @@ - (void)toggleProjectForAppAtIndex:(int)index {
295
310
break ;
296
311
}
297
312
}
298
- // For non-default apps, `nil` is considered the next option after the last options in the array.
299
- int useNil = index > 0 ;
300
- optionIndex = (optionIndex + 1 + useNil) % (gFirebaseAppOptions .count + useNil) - useNil;
301
- FIROptions *options = optionIndex >= 0 ? gFirebaseAppOptions [optionIndex] : nil ;
313
+
314
+ FIROptions *options;
315
+ if (index == 0 ) {
316
+ // For default apps, the next options cannot be `nil`.
317
+ optionIndex = (optionIndex + 1 ) % gFirebaseAppOptions .count ;
318
+ options = gFirebaseAppOptions [optionIndex];
319
+ } else {
320
+ // For non-default apps, `nil` is considered the next options after the last options in the array.
321
+ optionIndex = (optionIndex + 1 ) % (gFirebaseAppOptions .count + 1 );
322
+ if (optionIndex != gFirebaseAppOptions .count ) {
323
+ options = gFirebaseAppOptions [optionIndex];
324
+ }
325
+ }
302
326
__weak typeof (self) weakSelf = self;
303
327
[[AppManager sharedInstance ] recreateAppAtIndex: index withOptions: options completion: ^() {
304
328
dispatch_async (dispatch_get_main_queue (), ^() {
0 commit comments