Skip to content

Commit 3e2d705

Browse files
authored
Fix auth multi app support (#2043)
1 parent 5026453 commit 3e2d705

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

Example/Auth/Sample/AppManager.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222

2323
NS_ASSUME_NONNULL_BEGIN
2424

25-
// Declares a private method of FIRInstanceID to work around a bug.
26-
@interface FIRInstanceID : NSObject
27-
+ (void)notifyTokenRefresh;
28-
@end
29-
3025
@implementation AppManager {
3126
/** @var _createdAppNames
3227
@brief The set of names of live (created but not deleted) app, to avoid iCore warnings.
@@ -59,7 +54,6 @@ - (void)recreateAppAtIndex:(int)index
5954
completion:(void (^)())completion {
6055
[self deleteAppAtIndex:index completion:^() {
6156
if (index == 0) {
62-
[FIRInstanceID notifyTokenRefresh]; // b/28967043
6357
if (options) {
6458
[FIRApp configureWithOptions:options];
6559
}

Example/Auth/Sample/SettingsViewController.m

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ - (NSString *)projectIDForAppAtIndex:(int)index {
281281
return @"[none]";
282282
}
283283

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+
284299
/** @fn toggleProjectForAppAtIndex:
285300
@brief Toggles the Firebase project for the Firebase app at the given index by recreating the
286301
FIRApp instance with different options.
@@ -295,10 +310,19 @@ - (void)toggleProjectForAppAtIndex:(int)index {
295310
break;
296311
}
297312
}
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+
}
302326
__weak typeof(self) weakSelf = self;
303327
[[AppManager sharedInstance] recreateAppAtIndex:index withOptions:options completion:^() {
304328
dispatch_async(dispatch_get_main_queue(), ^() {

0 commit comments

Comments
 (0)