Skip to content

Commit 2448546

Browse files
committed
fix(ios): fix broken ios code from #4354
1 parent 8a1cf68 commit 2448546

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

packages/firebase_dynamic_links/ios/Classes/FLTFirebaseDynamicLinksPlugin.m

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,18 @@ - (void)onDeepLinkResult:(FIRDynamicLink *_Nullable)dynamicLink error:(NSError *
138138
}
139139
}
140140

141-
- (BOOL)checkForDynamicLink:(NSURL *)url {
141+
- (void)checkForDynamicLink:(NSURL *)url {
142142
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
143143
if (dynamicLink) {
144144
[self onDeepLinkResult:dynamicLink error:nil];
145-
return YES;
146145
}
147-
return NO;
148146
}
149147

150148
- (BOOL)application:(UIApplication *)application
151149
openURL:(NSURL *)url
152150
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
153151
[self checkForDynamicLink:url];
154-
// results of this are ORed and NO doesn't affect other delegate interceptors' result
152+
// Results of this are ORed and NO doesn't affect other delegate interceptors' result.
155153
return NO;
156154
}
157155

@@ -160,49 +158,48 @@ - (BOOL)application:(UIApplication *)application
160158
sourceApplication:(NSString *)sourceApplication
161159
annotation:(id)annotation {
162160
[self checkForDynamicLink:url];
163-
// results of this are ORed and NO doesn't affect other delegate interceptors' result
161+
// Results of this are ORed and NO doesn't affect other delegate interceptors' result.
164162
return NO;
165163
}
166164

167165
- (BOOL)application:(UIApplication *)application
168166
continueUserActivity:(NSUserActivity *)userActivity
169-
restorationHandler:
170-
#if defined(__IPHONE_12_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
171-
(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
172-
#else
173-
(nonnull void (^)(NSArray *_Nullable))restorationHandler {
174-
#endif // __IPHONE_12_0
167+
restorationHandler:(nonnull void (^)(NSArray *_Nullable))restorationHandler {
175168
__block BOOL retried = NO;
169+
void (^completionBlock)(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error);
170+
void (^__block __weak weakCompletionBlock)(FIRDynamicLink *_Nullable dynamicLink,
171+
NSError *_Nullable error);
172+
weakCompletionBlock = completionBlock = ^(FIRDynamicLink *_Nullable dynamicLink,
173+
NSError *_Nullable error) {
174+
if (!error && dynamicLink && dynamicLink.url) {
175+
[self onDeepLinkResult:dynamicLink error:nil];
176+
}
176177

177-
id completion =
178-
^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
179-
if (!error && dynamicLink && dynamicLink.url) {
180-
[self onDeepLinkResult:dynamicLink error:nil];
181-
}
182-
}
183-
// Per Apple Tech Support, a network failure could occur when returning from background on
184-
// iOS 12. https://github.com/AFNetworking/AFNetworking/issues/4279#issuecomment-447108981 So
185-
// we'll retry the request once
186-
if (error && !retried && [NSPOSIXErrorDomain isEqualToString:error.domain] &&
187-
error.code == 53) {
188-
retried = YES;
189-
[[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
190-
completion:completion];
191-
}
192-
// We could send this to Dart and maybe have a onDynamicLinkError stream but there's also
193-
// a good chance the `userActivity.webpageURL` might not be for a Firebase dynamic link,
194-
// which needs consideration - so we'll log this for now, logging will get picked up by
195-
// Crashlytics automatically if its integrated.
196-
if (error)
197-
NSLog(@"FLTFirebaseDynamicLinks: Unknown error occurred when attempting to handle a universal "
178+
// Per Apple Tech Support, a network failure could occur when returning from background on
179+
// iOS 12. https://github.com/AFNetworking/AFNetworking/issues/4279#issuecomment-447108981 So
180+
// we'll retry the request once
181+
if (error && !retried && [NSPOSIXErrorDomain isEqualToString:error.domain] &&
182+
error.code == 53) {
183+
retried = YES;
184+
[[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
185+
completion:weakCompletionBlock];
186+
}
187+
// We could send this to Dart and maybe have a onDynamicLinkError stream but there's also
188+
// a good chance the `userActivity.webpageURL` might not be for a Firebase dynamic link,
189+
// which needs consideration - so we'll log this for now, logging will get picked up by
190+
// Crashlytics automatically if its integrated.
191+
if (error)
192+
NSLog(
193+
@"FLTFirebaseDynamicLinks: Unknown error occurred when attempting to handle a universal "
198194
@"link: %@",
199195
error);
200-
};
196+
};
201197

202-
[[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL completion:completion];
198+
[[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
199+
completion:completionBlock];
203200

204-
// results of this are ORed and NO doesn't affect other delegate interceptors' result
205-
return NO;
201+
// Results of this are ORed and NO doesn't affect other delegate interceptors' result.
202+
return NO;
206203
}
207204

208205
- (FIRDynamicLinkShortenerCompletion)createShortLinkCompletion:(FlutterResult)result {

0 commit comments

Comments
 (0)