Skip to content

Commit dadcce8

Browse files
authored
Avoid using default FIROptions directly. (#2124)
Instead of using `[FIROptions defaultOptions]` we should be using `FIRApp`'s options. This will allow developers to use custom `FIROptions` instead of the default named Info.plist.
1 parent 471c23f commit dadcce8

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

Firebase/DynamicLinks/FDLURLComponents/FIRDynamicLinkComponentsKeyProvider.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19-
NS_ASSUME_NONNULL_BEGIN
20-
2119
@interface FIRDynamicLinkComponentsKeyProvider : NSObject
2220

23-
+ (NSString *)APIKey;
21+
+ (nullable NSString *)APIKey;
2422

2523
@end
26-
27-
NS_ASSUME_NONNULL_END

Firebase/DynamicLinks/FDLURLComponents/FIRDynamicLinkComponentsKeyProvider.m

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616

1717
#import "DynamicLinks/FDLURLComponents/FIRDynamicLinkComponentsKeyProvider.h"
1818

19+
#import <FirebaseCore/FIRAppInternal.h>
1920
#import <FirebaseCore/FIROptions.h>
2021

21-
NS_ASSUME_NONNULL_BEGIN
22-
2322
@implementation FIRDynamicLinkComponentsKeyProvider
2423

25-
+ (NSString *)APIKey {
26-
static NSString *apiKey;
27-
static dispatch_once_t onceToken;
28-
dispatch_once(&onceToken, ^{
29-
apiKey = [FIROptions defaultOptions].APIKey;
30-
});
31-
return apiKey;
24+
+ (nullable NSString *)APIKey {
25+
// If there's no default app, immediately return nil since reading from the default app will cause
26+
// an error to be logged.
27+
if (![FIRApp isDefaultAppConfigured]) {
28+
return nil;
29+
}
30+
31+
// FDL only supports the default app, use the options from it.
32+
return [FIRApp defaultApp].options.APIKey;
3233
}
3334

3435
@end
35-
36-
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)