Skip to content

Commit b3bebbd

Browse files
authored
Add support for initializing custom domains without Core. This is required for 1P. (#3540)
1 parent 0358696 commit b3bebbd

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

Example/DynamicLinks/Tests/FIRDynamicLinksTest.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,27 @@ - (void)testUniversalLink_NoDeepLink {
513513
XCTAssertNil(dynamicLink, @"invite should be nil since there is no parameter.");
514514
}
515515

516+
// Custom domain entries in plist file:
517+
// https://google.com
518+
// https://google.com/one
519+
// https://a.firebase.com/mypath
520+
- (void)testDynamicLinkFromUniversalLinkURLWithCustomDomainLink {
521+
self.service = [[FIRDynamicLinks alloc] init];
522+
NSString *durableDeepLinkString = @"https://a.firebase.com/mypath/?link=abcd";
523+
NSURL *durabledeepLinkURL = [NSURL URLWithString:durableDeepLinkString];
524+
525+
SwizzleDynamicLinkNetworkingWithMock();
526+
527+
FIRDynamicLink *dynamicLink = [self.service dynamicLinkFromUniversalLinkURL:durabledeepLinkURL];
528+
529+
XCTAssertNotNil(dynamicLink);
530+
NSString *deepLinkURLString = dynamicLink.url.absoluteString;
531+
532+
XCTAssertEqualObjects(@"abcd", deepLinkURLString,
533+
@"ddl url parameter and deep link url should be the same");
534+
UnswizzleDynamicLinkNetworking();
535+
}
536+
516537
- (void)testDynamicLinkFromUniversalLinkURLWithSpecialCharacters {
517538
NSString *durableDeepLinkString =
518539
[NSString stringWithFormat:@"https://xyz.page.link/?link=%@", kEncodedComplicatedURLString];

Firebase/DynamicLinks/FIRDynamicLinks.m

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,7 @@ - (void)configureDynamicLinks:(FIRApp *)app {
220220
}
221221
[NSException raise:kFirebaseDurableDeepLinkErrorDomain format:@"%@", message];
222222
}
223-
// Check to see if FirebaseDynamicLinksCustomDomains array is present.
224-
NSDictionary *infoDictionary = [NSBundle mainBundle].infoDictionary;
225-
NSArray *customDomains = infoDictionary[kInfoPlistCustomDomainsKey];
226-
if (customDomains) {
227-
FIRDLAddToAllowListForCustomDomainsArray(customDomains);
228-
}
223+
[self checkForCustomDomainEntriesInInfoPlist];
229224
}
230225
231226
- (instancetype)initWithAnalytics:(nullable id<FIRAnalyticsInterop>)analytics {
@@ -254,6 +249,26 @@ + (instancetype)dynamicLinks {
254249
}
255250
#endif
256251
252+
#pragma mark - Custom domains
253+
254+
- (instancetype)init {
255+
self = [super init];
256+
if (self) {
257+
[self checkForCustomDomainEntriesInInfoPlist];
258+
}
259+
return self;
260+
}
261+
262+
// Check for custom domains entry in PLIST file.
263+
- (void)checkForCustomDomainEntriesInInfoPlist {
264+
// Check to see if FirebaseDynamicLinksCustomDomains array is present.
265+
NSDictionary *infoDictionary = [NSBundle mainBundle].infoDictionary;
266+
NSArray *customDomains = infoDictionary[kInfoPlistCustomDomainsKey];
267+
if (customDomains) {
268+
FIRDLAddToAllowListForCustomDomainsArray(customDomains);
269+
}
270+
}
271+
257272
#pragma mark - First party interface
258273
259274
- (BOOL)setUpWithLaunchOptions:(nullable NSDictionary *)launchOptions

0 commit comments

Comments
 (0)