26
26
#import " FirebaseDynamicLinks/Sources/FIRDynamicLinkNetworking.h"
27
27
#import " FirebaseDynamicLinks/Sources/Utilities/FDLUtilities.h"
28
28
29
- // The maximum number of successful fingerprint api calls.
30
- const static NSUInteger kMaximumNumberOfSuccessfulFingerprintAPICalls = 2 ;
31
-
32
29
// Reason for this string to ensure that only FDL links, copied to clipboard by AppPreview Page
33
30
// JavaScript code, are recognized and used in copy-unique-match process. If user copied FDL to
34
31
// clipboard by himself, that link must not be used in copy-unique-match process.
40
37
41
38
@interface FIRDLDefaultRetrievalProcessV2 () <FIRDLJavaScriptExecutorDelegate>
42
39
43
- @property (atomic , strong ) NSMutableArray *requestResults;
44
-
45
40
@end
46
41
47
42
@implementation FIRDLDefaultRetrievalProcessV2 {
@@ -71,8 +66,6 @@ - (instancetype)initWithNetworkingService:(FIRDynamicLinkNetworking *)networking
71
66
_URLScheme = [URLScheme copy ];
72
67
_APIKey = [APIKey copy ];
73
68
_FDLSDKVersion = [FDLSDKVersion copy ];
74
- self.requestResults =
75
- [[NSMutableArray alloc ] initWithCapacity: kMaximumNumberOfSuccessfulFingerprintAPICalls ];
76
69
_delegate = delegate;
77
70
}
78
71
return self;
@@ -88,10 +81,6 @@ - (void)retrievePendingDynamicLink {
88
81
}
89
82
}
90
83
91
- - (BOOL )isCompleted {
92
- return self.requestResults .count >= kMaximumNumberOfSuccessfulFingerprintAPICalls ;
93
- }
94
-
95
84
#pragma mark - FIRDLJavaScriptExecutorDelegate
96
85
97
86
- (void )javaScriptExecutor : (FIRDLJavaScriptExecutor *)executor
@@ -130,11 +119,6 @@ - (void)retrievePendingDynamicLinkInternal {
130
119
if (!strongSelf) {
131
120
return ;
132
121
}
133
- if (strongSelf.completed ) {
134
- // we may abort process and return previously found dynamic link before all requests
135
- // completed
136
- return ;
137
- }
138
122
139
123
FIRDynamicLink *dynamicLink;
140
124
if (dynamicLinkParameters.count ) {
@@ -146,8 +130,7 @@ - (void)retrievePendingDynamicLinkInternal {
146
130
message: matchMessage
147
131
matchSource: nil ];
148
132
149
- [strongSelf.requestResults addObject: result];
150
- [strongSelf handleRequestResultsUpdated ];
133
+ [strongSelf handleRetrievalProcessWithResult: result];
151
134
if (!error) {
152
135
[strongSelf clearUsedUniqueMatchLinkToCheckFromClipboard ];
153
136
}
@@ -156,8 +139,7 @@ - (void)retrievePendingDynamicLinkInternal {
156
139
// Disable deprecated warning for internal methods.
157
140
#pragma clang diagnostic push
158
141
#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.
161
143
[_networkingService
162
144
retrievePendingDynamicLinkWithIOSVersion: [UIDevice currentDevice ].systemVersion
163
145
resolutionHeight: resolutionHeight
@@ -177,94 +159,17 @@ - (void)retrievePendingDynamicLinkInternal {
177
159
#pragma clang pop
178
160
}
179
161
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 ];
267
171
}
172
+ [self .delegate retrievalProcess: self completedWithResult: result];
268
173
}
269
174
270
175
- (nullable NSURL *)uniqueMatchLinkToCheck {
0 commit comments