Skip to content

Commit c5501e6

Browse files
authored
Ipv4 ipv6 fix (#6428)
Recreating PR #5966 Instead of using firebasedynamiclinks-ipv4.googleapis.com and firebasedynamiclinks-ipv6.googleapis.com for doing attribution calls, we are moving towards using firebasedynamiclinks.googleapis.com. Fixes #5032 -changed ipv4 and ipv6 attribution calls with a single direct url. -Removed and refactored code to get rid of code to handle consolidated results from ipv4 and ipv6 result. -Made changes to Test app to show alert dialog when universal linking when app is not in background case and also for fresh start case.
1 parent 9700e26 commit c5501e6

File tree

6 files changed

+51
-178
lines changed

6 files changed

+51
-178
lines changed

FirebaseDynamicLinks/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# v4.3.1
22
- [changed] Client id usage in api call and respective checks in the code.
3+
- [fixed] Fix attempts to connect to invalid ipv6 domain by updating ipv4 and ipv6 to use a single, valid endpoint (#5032)
34

45
# v4.3.0
56
- [changed] Functionally neutral public header refactor to enable Swift Package

FirebaseDynamicLinks/Sources/FIRDLDefaultRetrievalProcessV2.m

Lines changed: 12 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
#import "FirebaseDynamicLinks/Sources/FIRDynamicLinkNetworking.h"
2727
#import "FirebaseDynamicLinks/Sources/Utilities/FDLUtilities.h"
2828

29-
// The maximum number of successful fingerprint api calls.
30-
const static NSUInteger kMaximumNumberOfSuccessfulFingerprintAPICalls = 2;
31-
3229
// Reason for this string to ensure that only FDL links, copied to clipboard by AppPreview Page
3330
// JavaScript code, are recognized and used in copy-unique-match process. If user copied FDL to
3431
// clipboard by himself, that link must not be used in copy-unique-match process.
@@ -40,8 +37,6 @@
4037

4138
@interface FIRDLDefaultRetrievalProcessV2 () <FIRDLJavaScriptExecutorDelegate>
4239

43-
@property(atomic, strong) NSMutableArray *requestResults;
44-
4540
@end
4641

4742
@implementation FIRDLDefaultRetrievalProcessV2 {
@@ -71,8 +66,6 @@ - (instancetype)initWithNetworkingService:(FIRDynamicLinkNetworking *)networking
7166
_URLScheme = [URLScheme copy];
7267
_APIKey = [APIKey copy];
7368
_FDLSDKVersion = [FDLSDKVersion copy];
74-
self.requestResults =
75-
[[NSMutableArray alloc] initWithCapacity:kMaximumNumberOfSuccessfulFingerprintAPICalls];
7669
_delegate = delegate;
7770
}
7871
return self;
@@ -88,10 +81,6 @@ - (void)retrievePendingDynamicLink {
8881
}
8982
}
9083

91-
- (BOOL)isCompleted {
92-
return self.requestResults.count >= kMaximumNumberOfSuccessfulFingerprintAPICalls;
93-
}
94-
9584
#pragma mark - FIRDLJavaScriptExecutorDelegate
9685

9786
- (void)javaScriptExecutor:(FIRDLJavaScriptExecutor *)executor
@@ -130,11 +119,6 @@ - (void)retrievePendingDynamicLinkInternal {
130119
if (!strongSelf) {
131120
return;
132121
}
133-
if (strongSelf.completed) {
134-
// we may abort process and return previously found dynamic link before all requests
135-
// completed
136-
return;
137-
}
138122

139123
FIRDynamicLink *dynamicLink;
140124
if (dynamicLinkParameters.count) {
@@ -146,8 +130,7 @@ - (void)retrievePendingDynamicLinkInternal {
146130
message:matchMessage
147131
matchSource:nil];
148132

149-
[strongSelf.requestResults addObject:result];
150-
[strongSelf handleRequestResultsUpdated];
133+
[strongSelf handleRetrievalProcessWithResult:result];
151134
if (!error) {
152135
[strongSelf clearUsedUniqueMatchLinkToCheckFromClipboard];
153136
}
@@ -156,8 +139,7 @@ - (void)retrievePendingDynamicLinkInternal {
156139
// Disable deprecated warning for internal methods.
157140
#pragma clang diagnostic push
158141
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
159-
// If not unique match, we send request twice, since there are two server calls:
160-
// one for IPv4, another for IPV6.
142+
// If there is not a unique match, we will send an additional request for fingerprinting.
161143
[_networkingService
162144
retrievePendingDynamicLinkWithIOSVersion:[UIDevice currentDevice].systemVersion
163145
resolutionHeight:resolutionHeight
@@ -177,94 +159,17 @@ - (void)retrievePendingDynamicLinkInternal {
177159
#pragma clang pop
178160
}
179161

180-
- (NSArray<FIRDLRetrievalProcessResult *> *)foundResultsWithDynamicLinks {
181-
NSPredicate *predicate =
182-
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
183-
NSDictionary<NSString *, id> *_Nullable bindings) {
184-
if ([evaluatedObject isKindOfClass:[FIRDLRetrievalProcessResult class]]) {
185-
FIRDLRetrievalProcessResult *result = (FIRDLRetrievalProcessResult *)evaluatedObject;
186-
return result.dynamicLink.url != nil;
187-
}
188-
return NO;
189-
}];
190-
return [self.requestResults filteredArrayUsingPredicate:predicate];
191-
}
192-
193-
- (NSArray<FIRDLRetrievalProcessResult *> *)resultsWithErrors {
194-
NSPredicate *predicate =
195-
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
196-
NSDictionary<NSString *, id> *_Nullable bindings) {
197-
if ([evaluatedObject isKindOfClass:[FIRDLRetrievalProcessResult class]]) {
198-
FIRDLRetrievalProcessResult *result = (FIRDLRetrievalProcessResult *)evaluatedObject;
199-
return result.error != nil;
200-
}
201-
return NO;
202-
}];
203-
return [self.requestResults filteredArrayUsingPredicate:predicate];
204-
}
205-
206-
- (NSArray<FIRDLRetrievalProcessResult *> *)results {
207-
NSPredicate *predicate =
208-
[NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject,
209-
NSDictionary<NSString *, id> *_Nullable bindings) {
210-
return [evaluatedObject isKindOfClass:[FIRDLRetrievalProcessResult class]];
211-
}];
212-
return [self.requestResults filteredArrayUsingPredicate:predicate];
213-
}
214-
215-
- (nullable FIRDLRetrievalProcessResult *)resultWithUniqueMatchedDynamicLink {
216-
// return result with unique-matched dynamic link if found
217-
NSArray<FIRDLRetrievalProcessResult *> *foundResultsWithDynamicLinks =
218-
[self foundResultsWithDynamicLinks];
219-
for (FIRDLRetrievalProcessResult *result in foundResultsWithDynamicLinks) {
220-
if (result.dynamicLink.matchType == FIRDLMatchTypeUnique) {
221-
return result;
222-
}
223-
}
224-
return nil;
225-
}
226-
227-
- (void)handleRequestResultsUpdated {
228-
FIRDLRetrievalProcessResult *resultWithUniqueMatchedDynamicLink =
229-
[self resultWithUniqueMatchedDynamicLink];
230-
if (resultWithUniqueMatchedDynamicLink) {
231-
[self markCompleted];
232-
[self.delegate retrievalProcess:self completedWithResult:resultWithUniqueMatchedDynamicLink];
233-
} else if (self.completed) {
234-
NSArray<FIRDLRetrievalProcessResult *> *foundResultsWithDynamicLinks =
235-
[self foundResultsWithDynamicLinks];
236-
NSArray<FIRDLRetrievalProcessResult *> *resultsThatEncounteredErrors = [self resultsWithErrors];
237-
if (foundResultsWithDynamicLinks.count) {
238-
// return any result if no unique-matched URL is available
239-
// TODO: Merge match message from all results
240-
[self.delegate retrievalProcess:self
241-
completedWithResult:foundResultsWithDynamicLinks.firstObject];
242-
} else if (resultsThatEncounteredErrors.count > 0) {
243-
// TODO: Merge match message and errors from all results
244-
[self.delegate retrievalProcess:self
245-
completedWithResult:resultsThatEncounteredErrors.firstObject];
246-
} else {
247-
// dynamic link not found
248-
// TODO: Merge match message from all results
249-
FIRDLRetrievalProcessResult *result = [[self results] firstObject];
250-
if (!result) {
251-
// if we did not get any results, construct one
252-
NSString *message = NSLocalizedString(@"Pending dynamic link not found",
253-
@"Message when dynamic link was not found");
254-
result = [[FIRDLRetrievalProcessResult alloc] initWithDynamicLink:nil
255-
error:nil
256-
message:message
257-
matchSource:nil];
258-
}
259-
[self.delegate retrievalProcess:self completedWithResult:result];
260-
}
261-
}
262-
}
263-
264-
- (void)markCompleted {
265-
while (!self.completed) {
266-
[self.requestResults addObject:[NSNull null]];
162+
- (void)handleRetrievalProcessWithResult:(FIRDLRetrievalProcessResult *)result {
163+
if (!result) {
164+
// if we did not get any results, construct one
165+
NSString *message = NSLocalizedString(@"Pending dynamic link not found",
166+
@"Message when dynamic link was not found");
167+
result = [[FIRDLRetrievalProcessResult alloc] initWithDynamicLink:nil
168+
error:nil
169+
message:message
170+
matchSource:nil];
267171
}
172+
[self.delegate retrievalProcess:self completedWithResult:result];
268173
}
269174

270175
- (nullable NSURL *)uniqueMatchLinkToCheck {

FirebaseDynamicLinks/Sources/FIRDLRetrievalProcessProtocols.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ NS_ASSUME_NONNULL_BEGIN
3131
@protocol FIRDLRetrievalProcessProtocol <NSObject>
3232

3333
@property(weak, nonatomic, readonly) id<FIRDLRetrievalProcessDelegate> delegate;
34-
@property(nonatomic, readonly, getter=isCompleted) BOOL completed;
3534

3635
- (void)retrievePendingDynamicLink;
3736

FirebaseDynamicLinks/Sources/FIRDynamicLinkNetworking.m

Lines changed: 23 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,8 @@
2828
NSString *const kApiaryRestBaseUrl = @"https://appinvite-pa.googleapis.com/v1";
2929
static NSString *const kiOSReopenRestBaseUrl = @"https://firebasedynamiclinks.googleapis.com/v1";
3030

31-
// IPv4 and IPv6 Endpoints.
32-
static NSString *const kApiaryRestBaseUrlIPV4 = @"https://appinvite-ipv4-pa.googleapis.com/v1";
33-
static NSString *const kApiaryRestBaseUrlIPV6 = @"https://appinvite-ipv6-pa.googleapis.com/v1";
34-
35-
// IPv4 and IPv6 Endpoints for default retrieval process V2. (Endpoint version is V1)
36-
static NSString *const kIosPostInstallAttributionRestBaseUrlIPV4 =
37-
@"https://firebasedynamiclinks-ipv4.googleapis.com/v1";
38-
static NSString *const kIosPostInstallAttributionRestBaseUrlIPV6 =
39-
@"https://firebasedynamiclinks-ipv6.googleapis.com/v1";
40-
static NSString *const kIosPostInstallAttributionRestBaseUrlUniqueMatch =
31+
// Endpoint for default retrieval process V2. (Endpoint version is V1)
32+
static NSString *const kIosPostInstallAttributionRestBaseUrl =
4133
@"https://firebasedynamiclinks.googleapis.com/v1";
4234

4335
static NSString *const kReasonString = @"reason";
@@ -230,19 +222,11 @@ - (void)retrievePendingDynamicLinkWithIOSVersion:(NSString *)IOSVersion
230222
return [dynamicLinkParameters copy];
231223
};
232224

233-
// If uniqueMatch link available send to the unique match endpoint,
234-
// else send requests to both IPv4 and IPv6 endpoints.
235-
NSArray *baseURLs =
236-
uniqueMatchLinkToCheck ? @[ kIosPostInstallAttributionRestBaseUrlUniqueMatch ] : @[
237-
kIosPostInstallAttributionRestBaseUrlIPV4, kIosPostInstallAttributionRestBaseUrlIPV6
238-
];
239-
for (NSString *baseURL in baseURLs) {
240-
[self sendRequestWithBaseURLString:baseURL
241-
requestBody:requestBody
242-
endpointPath:@"installAttribution"
243-
parserBlock:responseParserBlock
244-
completion:handler];
245-
}
225+
[self sendRequestWithBaseURLString:kIosPostInstallAttributionRestBaseUrl
226+
requestBody:requestBody
227+
endpointPath:@"installAttribution"
228+
parserBlock:responseParserBlock
229+
completion:handler];
246230
}
247231

248232
- (void)convertInvitation:(NSString *)invitationID
@@ -285,54 +269,24 @@ - (void)sendRequestWithBaseURLString:(NSString *)baseURL
285269
NSString *requestURLString = [NSString
286270
stringWithFormat:@"%@/%@%@", baseURL, endpointPath, FIRDynamicLinkAPIKeyParameter(_APIKey)];
287271

288-
FIRNetworkRequestCompletionHandler completeInvitationByDeviceCallback = ^(NSData *data,
289-
NSError *error) {
290-
if (error || !data) {
291-
dispatch_async(dispatch_get_main_queue(), ^{
292-
handler(nil, nil, error);
293-
});
294-
return;
295-
}
296-
NSString *matchMessage = nil;
297-
NSError *parsingError = nil;
298-
NSDictionary *parsedDynamicLinkParameters =
299-
parserBlock(requestURLString, data, &matchMessage, &parsingError);
300-
301-
// If request was made with pasteboard contents, verify if we got a unique match. If we got
302-
// a "none" match, we were unable to get a unique match or deduce using fingerprinting.
303-
// In this case, resend requests to IPV4 and IPV6 endpoints for fingerprinting. b/79704203
304-
if (requestBody[@"uniqueMatchLinkToCheck"] && parsedDynamicLinkParameters &&
305-
(!parsedDynamicLinkParameters[kFIRDLParameterMatchType] ||
306-
[parsedDynamicLinkParameters[kFIRDLParameterMatchType] isEqualToString:@"none"])) {
307-
NSMutableDictionary *requestBodyMutable = [requestBody mutableCopy];
308-
[requestBodyMutable removeObjectForKey:@"uniqueMatchLinkToCheck"];
309-
NSMutableArray *baseURLs =
310-
[@[ kIosPostInstallAttributionRestBaseUrlIPV4, kIosPostInstallAttributionRestBaseUrlIPV6 ]
311-
mutableCopy];
312-
if (parsedDynamicLinkParameters[kFIRDLParameterRequestIPVersion]) {
313-
if ([parsedDynamicLinkParameters[kFIRDLParameterRequestIPVersion]
314-
isEqualToString:@"IP_V4"]) {
315-
[baseURLs removeObject:kIosPostInstallAttributionRestBaseUrlIPV4];
316-
} else if ([parsedDynamicLinkParameters[kFIRDLParameterRequestIPVersion]
317-
isEqualToString:@"IP_V6"]) {
318-
[baseURLs removeObject:kIosPostInstallAttributionRestBaseUrlIPV6];
272+
FIRNetworkRequestCompletionHandler completeInvitationByDeviceCallback =
273+
^(NSData *data, NSError *error) {
274+
if (error || !data) {
275+
dispatch_async(dispatch_get_main_queue(), ^{
276+
handler(nil, nil, error);
277+
});
278+
return;
319279
}
320-
}
321280

322-
for (NSString *baseURL in baseURLs) {
323-
[self sendRequestWithBaseURLString:baseURL
324-
requestBody:requestBodyMutable
325-
endpointPath:@"installAttribution"
326-
parserBlock:parserBlock
327-
completion:handler];
328-
}
329-
}
330-
// We want to return out the result of the unique match check irrespective of success/failure as
331-
// it is the first fingerprinting request as well.
332-
dispatch_async(dispatch_get_main_queue(), ^{
333-
handler(parsedDynamicLinkParameters, matchMessage, parsingError);
334-
});
335-
};
281+
NSString *matchMessage = nil;
282+
NSError *parsingError = nil;
283+
NSDictionary *parsedDynamicLinkParameters =
284+
parserBlock(requestURLString, data, &matchMessage, &parsingError);
285+
286+
dispatch_async(dispatch_get_main_queue(), ^{
287+
handler(parsedDynamicLinkParameters, matchMessage, parsingError);
288+
});
289+
};
336290

337291
[self executeOnePlatformRequest:requestBody
338292
forURL:requestURLString

FirebaseDynamicLinks/Tests/Sample/FDLBuilderTestAppObjC/AppDelegate.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ - (void)_showDynamicLinkInfo:(FIRDynamicLink *)dynamicLink {
9292
[alertVC addAction:[UIAlertAction actionWithTitle:@"Dismiss"
9393
style:UIAlertActionStyleCancel
9494
handler:NULL]];
95-
[self.window.rootViewController presentViewController:alertVC animated:YES completion:NULL];
95+
96+
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertVC
97+
animated:YES
98+
completion:NULL];
9699
}
97100

98101
@end

FirebaseDynamicLinks/Tests/Sample/FDLBuilderTestAppObjC/SceneDelegate.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ - (void)scene:(UIScene *)scene
3131
// UIWindowScene `scene`. If using a storyboard, the `window` property will automatically be
3232
// initialized and attached to the scene. This delegate does not imply the connecting scene or
3333
// session are new (see `application:configurationForConnectingSceneSession` instead).
34+
if (connectionOptions.userActivities && connectionOptions.userActivities.count > 0) {
35+
NSUserActivity *userActivity = connectionOptions.userActivities.allObjects.firstObject;
36+
[self handleDynamicLinkFromActivity:userActivity];
37+
}
3438
}
3539

3640
- (void)sceneDidDisconnect:(UIScene *)scene {
@@ -64,6 +68,13 @@ - (void)sceneDidEnterBackground:(UIScene *)scene {
6468
}
6569

6670
- (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity {
71+
[self handleDynamicLinkFromActivity:userActivity];
72+
}
73+
74+
- (void)handleDynamicLinkFromActivity:(NSUserActivity *)userActivity {
75+
if (!userActivity) {
76+
return;
77+
}
6778
BOOL handled = [[FIRDynamicLinks dynamicLinks]
6879
handleUniversalLink:userActivity.webpageURL
6980
completion:^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {

0 commit comments

Comments
 (0)