From b71b08602b3a32d992f714d8430c1f382e024082 Mon Sep 17 00:00:00 2001 From: Eldhose Mathokkil Babu Date: Thu, 21 May 2020 12:34:08 -0700 Subject: [PATCH 1/5] Fix for b/154589338 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- FirebaseDynamicLinks/Sources/FIRDynamicLinks.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m b/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m index aa4370ee4ce..f215d928ee9 100644 --- a/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m +++ b/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m @@ -554,9 +554,14 @@ - (void)retrievalProcess:(id)retrievalProcess self.retrievingPendingDynamicLink = NO; _retrievalProcess = nil; - if (!result.error && ![_userDefaults boolForKey:kFIRDLOpenURLKey]) { + if (![_userDefaults boolForKey:kFIRDLOpenURLKey]) { + //Once we complete the Pending dynamic link retrival, regardless of whether the retrival is + //success or failure, we don't want to do the retrival again on next app start. + //If we try to redo the retrival again because of some error, the user will experiance unwanted + //deeplinking when they restart the app next time. [_userDefaults setBool:YES forKey:kFIRDLOpenURLKey]; } + NSURL *linkToPassToApp = [result URLWithCustomURLScheme:_URLScheme]; [self passRetrievedDynamicLinkToApplication:linkToPassToApp]; } From 17a1933b2eda266ffa5f2f4cc13e9d1c0964b4e5 Mon Sep 17 00:00:00 2001 From: Eldhose Mathokkil Babu Date: Wed, 27 May 2020 12:23:19 -0700 Subject: [PATCH 2/5] Fix styling --- FirebaseDynamicLinks/Sources/FIRDynamicLinks.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m b/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m index f215d928ee9..49388968d9b 100644 --- a/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m +++ b/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m @@ -555,10 +555,10 @@ - (void)retrievalProcess:(id)retrievalProcess _retrievalProcess = nil; if (![_userDefaults boolForKey:kFIRDLOpenURLKey]) { - //Once we complete the Pending dynamic link retrival, regardless of whether the retrival is - //success or failure, we don't want to do the retrival again on next app start. - //If we try to redo the retrival again because of some error, the user will experiance unwanted - //deeplinking when they restart the app next time. + // Once we complete the Pending dynamic link retrival, regardless of whether the retrival is + // success or failure, we don't want to do the retrival again on next app start. + // If we try to redo the retrival again because of some error, the user will experiance unwanted + // deeplinking when they restart the app next time. [_userDefaults setBool:YES forKey:kFIRDLOpenURLKey]; } From 385e3fee5c34e8688ad02e06a9f525c9c276cf34 Mon Sep 17 00:00:00 2001 From: Eldhose Mathokkil Babu Date: Fri, 29 May 2020 10:28:42 -0700 Subject: [PATCH 3/5] Adding unit test. --- .../Tests/Unit/FIRDynamicLinksTest.m | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/FirebaseDynamicLinks/Tests/Unit/FIRDynamicLinksTest.m b/FirebaseDynamicLinks/Tests/Unit/FIRDynamicLinksTest.m index d714d219c8f..3aad5c2c6ae 100644 --- a/FirebaseDynamicLinks/Tests/Unit/FIRDynamicLinksTest.m +++ b/FirebaseDynamicLinks/Tests/Unit/FIRDynamicLinksTest.m @@ -23,6 +23,7 @@ #import #import #import +#import "FirebaseDynamicLinks/Sources/FIRDLDefaultRetrievalProcessV2.h" #import "FirebaseDynamicLinks/Sources/FIRDLRetrievalProcessFactory.h" #import "FirebaseDynamicLinks/Sources/FIRDLRetrievalProcessResult+Private.h" #import "FirebaseDynamicLinks/Sources/FIRDynamicLink+Private.h" @@ -1171,6 +1172,31 @@ - (void)test_multipleRequestsToRetrievePendingDeepLinkShouldNotCrash { isClassSelector:NO]; } +- (void)test_retrievePendingDeepLinkShouldSetkFIRDLOpenURLKeyRegardlessOfFailures { + [self.service setUpWithLaunchOptions:nil + apiKey:kAPIKey + clientID:kClientID + urlScheme:nil + userDefaults:[NSUserDefaults standardUserDefaults]]; + FIRDynamicLinks *deleagte = + (FIRDynamicLinks *)self.service; + + // Error Result to pass + FIRDLRetrievalProcessResult *result = [[FIRDLRetrievalProcessResult alloc] + initWithDynamicLink:nil + error:[NSError errorWithDomain:@"unknown domain" code:500 userInfo:nil] + message:nil + matchSource:nil]; + + FIRDLDefaultRetrievalProcessV2 *defaultRetrievalProcess = [FIRDLDefaultRetrievalProcessV2 alloc]; + + [deleagte retrievalProcess:defaultRetrievalProcess completedWithResult:result]; + + NSString *kFIRDLOpenURLKey = @"com.google.appinvite.openURL"; + XCTAssertEqual([[NSUserDefaults standardUserDefaults] boolForKey:kFIRDLOpenURLKey], YES, + @"kFIRDLOpenURL key should be set regardless of failures"); +} + #pragma mark - Self-diagnose tests - (void)testSelfDiagnoseWithNilCompletion { From 500ce6ae99cb1325a310c70cc284757bcb3b8637 Mon Sep 17 00:00:00 2001 From: Eldhose Mathokkil Babu Date: Fri, 29 May 2020 10:38:15 -0700 Subject: [PATCH 4/5] Correction in spelling --- FirebaseDynamicLinks/Sources/FIRDynamicLinks.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m b/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m index 49388968d9b..5c202182798 100644 --- a/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m +++ b/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m @@ -555,7 +555,7 @@ - (void)retrievalProcess:(id)retrievalProcess _retrievalProcess = nil; if (![_userDefaults boolForKey:kFIRDLOpenURLKey]) { - // Once we complete the Pending dynamic link retrival, regardless of whether the retrival is + // Once we complete the Pending dynamic link retrieval, regardless of whether the retrival is // success or failure, we don't want to do the retrival again on next app start. // If we try to redo the retrival again because of some error, the user will experiance unwanted // deeplinking when they restart the app next time. From af6037b69d82619d6d155a12215f3aa49b173a61 Mon Sep 17 00:00:00 2001 From: Eldhose Mathokkil Babu Date: Fri, 29 May 2020 11:50:38 -0700 Subject: [PATCH 5/5] Addressing code review comments. --- FirebaseDynamicLinks/CHANGELOG.md | 3 +++ FirebaseDynamicLinks/Sources/FIRDynamicLinks.m | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/FirebaseDynamicLinks/CHANGELOG.md b/FirebaseDynamicLinks/CHANGELOG.md index 86b1b17f41a..221951943ae 100644 --- a/FirebaseDynamicLinks/CHANGELOG.md +++ b/FirebaseDynamicLinks/CHANGELOG.md @@ -1,3 +1,6 @@ +# Unreleased +- [fixed] Fixing unwanted pending dynamic links checks on subsequent app restarts + # v4.0.8 -- M67 - [fixed] Fix Catalyst build - removed deprecated unused Apple framework dependencies. (#5139) diff --git a/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m b/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m index 5c202182798..2a6be1d39d1 100644 --- a/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m +++ b/FirebaseDynamicLinks/Sources/FIRDynamicLinks.m @@ -555,10 +555,10 @@ - (void)retrievalProcess:(id)retrievalProcess _retrievalProcess = nil; if (![_userDefaults boolForKey:kFIRDLOpenURLKey]) { - // Once we complete the Pending dynamic link retrieval, regardless of whether the retrival is - // success or failure, we don't want to do the retrival again on next app start. - // If we try to redo the retrival again because of some error, the user will experiance unwanted - // deeplinking when they restart the app next time. + // Once we complete the Pending dynamic link retrieval, regardless of whether the retrieval is + // success or failure, we don't want to do the retrieval again on next app start. + // If we try to redo the retrieval again because of some error, the user will experience + // unwanted deeplinking when they restart the app next time. [_userDefaults setBool:YES forKey:kFIRDLOpenURLKey]; }