Skip to content

Commit 68b0a23

Browse files
authored
Fixing unwanted pending dynamic links checks on subsequent app restarts (#5665)
* Fix for internal bug b/154589338 Most of the times, when the app is cold started, we are making api calls to: https://firebasedynamiclinks-ipv4.googleapis.com/v1 https://firebasedynamiclinks-ipv6.googleapis.com/v1 Until we get a successful response. But sometimes, if the device doesn’t have support for v6 endpoint and if the v4 endpoint doesn’t retrieve a valid dynamic link, it will return error. This mostly happens when user directly goes to App Store and installs an app which has fdl sdk integrated. For dynamic links, we want the app to retrieve the pending dynamic link on the very first start of the app after install so that 3p developers can deeplink to a particular page in the app. If the pending links retrieval failed during the first start, there is no point in retrying the retrieval during next restart since it could result in an un expected deep link for the user when they opens up the app for subsequent restarts (if a valid dynamic link is returned).
1 parent 45eeb54 commit 68b0a23

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

FirebaseDynamicLinks/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [fixed] Fixing unwanted pending dynamic links checks on subsequent app restarts
3+
14
# v4.0.8 -- M67
25
- [fixed] Fix Catalyst build - removed deprecated unused Apple framework dependencies. (#5139)
36

FirebaseDynamicLinks/Sources/FIRDynamicLinks.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,14 @@ - (void)retrievalProcess:(id<FIRDLRetrievalProcessProtocol>)retrievalProcess
554554
self.retrievingPendingDynamicLink = NO;
555555
_retrievalProcess = nil;
556556

557-
if (!result.error && ![_userDefaults boolForKey:kFIRDLOpenURLKey]) {
557+
if (![_userDefaults boolForKey:kFIRDLOpenURLKey]) {
558+
// Once we complete the Pending dynamic link retrieval, regardless of whether the retrieval is
559+
// success or failure, we don't want to do the retrieval again on next app start.
560+
// If we try to redo the retrieval again because of some error, the user will experience
561+
// unwanted deeplinking when they restart the app next time.
558562
[_userDefaults setBool:YES forKey:kFIRDLOpenURLKey];
559563
}
564+
560565
NSURL *linkToPassToApp = [result URLWithCustomURLScheme:_URLScheme];
561566
[self passRetrievedDynamicLinkToApplication:linkToPassToApp];
562567
}

FirebaseDynamicLinks/Tests/Unit/FIRDynamicLinksTest.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import <GoogleUtilities/GULSwizzler+Unswizzle.h>
2424
#import <GoogleUtilities/GULSwizzler.h>
2525
#import <OCMock/OCMock.h>
26+
#import "FirebaseDynamicLinks/Sources/FIRDLDefaultRetrievalProcessV2.h"
2627
#import "FirebaseDynamicLinks/Sources/FIRDLRetrievalProcessFactory.h"
2728
#import "FirebaseDynamicLinks/Sources/FIRDLRetrievalProcessResult+Private.h"
2829
#import "FirebaseDynamicLinks/Sources/FIRDynamicLink+Private.h"
@@ -1171,6 +1172,31 @@ - (void)test_multipleRequestsToRetrievePendingDeepLinkShouldNotCrash {
11711172
isClassSelector:NO];
11721173
}
11731174

1175+
- (void)test_retrievePendingDeepLinkShouldSetkFIRDLOpenURLKeyRegardlessOfFailures {
1176+
[self.service setUpWithLaunchOptions:nil
1177+
apiKey:kAPIKey
1178+
clientID:kClientID
1179+
urlScheme:nil
1180+
userDefaults:[NSUserDefaults standardUserDefaults]];
1181+
FIRDynamicLinks<FIRDLRetrievalProcessDelegate> *deleagte =
1182+
(FIRDynamicLinks<FIRDLRetrievalProcessDelegate> *)self.service;
1183+
1184+
// Error Result to pass
1185+
FIRDLRetrievalProcessResult *result = [[FIRDLRetrievalProcessResult alloc]
1186+
initWithDynamicLink:nil
1187+
error:[NSError errorWithDomain:@"unknown domain" code:500 userInfo:nil]
1188+
message:nil
1189+
matchSource:nil];
1190+
1191+
FIRDLDefaultRetrievalProcessV2 *defaultRetrievalProcess = [FIRDLDefaultRetrievalProcessV2 alloc];
1192+
1193+
[deleagte retrievalProcess:defaultRetrievalProcess completedWithResult:result];
1194+
1195+
NSString *kFIRDLOpenURLKey = @"com.google.appinvite.openURL";
1196+
XCTAssertEqual([[NSUserDefaults standardUserDefaults] boolForKey:kFIRDLOpenURLKey], YES,
1197+
@"kFIRDLOpenURL key should be set regardless of failures");
1198+
}
1199+
11741200
#pragma mark - Self-diagnose tests
11751201

11761202
- (void)testSelfDiagnoseWithNilCompletion {

0 commit comments

Comments
 (0)