Skip to content

Commit 936bbed

Browse files
committed
fix(dynamic_links): Not working on app start (#100)
1 parent 85da607 commit 936bbed

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

packages/firebase_dynamic_links/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.3+1
2+
3+
- **FIX**: fixes several issues on iOS (#3319).
4+
15
## 0.6.3
26

37
- **FEAT**: bump android `com.android.tools.build` & `'com.google.gms:google-services` versions (#4269).

packages/firebase_dynamic_links/ios/Classes/FLTFirebaseDynamicLinksPlugin.m

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,55 @@ - (BOOL)checkForDynamicLink:(NSURL *)url {
150150
- (BOOL)application:(UIApplication *)application
151151
openURL:(NSURL *)url
152152
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
153-
return [self checkForDynamicLink:url];
153+
[self checkForDynamicLink:url];
154+
// results of this are ORed and NO doesn't affect other delegate interceptors' result
155+
return NO;
154156
}
155157

156158
- (BOOL)application:(UIApplication *)application
157159
openURL:(NSURL *)url
158160
sourceApplication:(NSString *)sourceApplication
159161
annotation:(id)annotation {
160-
return [self checkForDynamicLink:url];
162+
[self checkForDynamicLink:url];
163+
// results of this are ORed and NO doesn't affect other delegate interceptors' result
164+
return NO;
161165
}
162166

163167
- (BOOL)application:(UIApplication *)application
164168
continueUserActivity:(NSUserActivity *)userActivity
165-
restorationHandler:(void (^)(NSArray *))restorationHandler {
166-
BOOL handled = [[FIRDynamicLinks dynamicLinks]
167-
handleUniversalLink:userActivity.webpageURL
168-
completion:^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
169-
[self onDeepLinkResult:dynamicLink error:error];
170-
}];
171-
return handled;
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
175+
__block BOOL retried = NO;
176+
177+
id completion = ^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
178+
if (!error && dynamicLink && dynamicLink.url) {
179+
[self onDeepLinkResult:dynamicLink error:nil];
180+
}
181+
}
182+
// Per Apple Tech Support, a network failure could occur when returning from background on
183+
// iOS 12. https://github.com/AFNetworking/AFNetworking/issues/4279#issuecomment-447108981 So
184+
// we'll retry the request once
185+
if (error && !retried && [NSPOSIXErrorDomain isEqualToString:error.domain] &&
186+
error.code == 53) {
187+
retried = YES;
188+
[[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
189+
completion:completion];
190+
}
191+
// TODO: We could send this to Dart and maybe have a onDynamicLinkError listener but there's also a good chance the
192+
// TODO: `userActivity.webpageURL` might not be for a Firebase dynamic link, which needs consideration - so we'll
193+
// TODO: log this for now, logging will get picked up by Crashlytics automatically if its integrated.
194+
if (error) NSLog(@"FLTFirebaseDynamicLinks: Unknown error occurred when attempting to handle a universal link: %@", error);
195+
};
196+
197+
[[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
198+
completion:completion];
199+
200+
// results of this are ORed and NO doesn't affect other delegate interceptors' result
201+
return NO;
172202
}
173203

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

packages/firebase_dynamic_links/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: firebase_dynamic_links
22
description: Flutter plugin for Google Dynamic Links for Firebase, an app solution for creating
33
and handling links across multiple platforms.
4-
version: 0.6.3
4+
version: 0.6.3+1
55
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_dynamic_links
66

77
dependencies:

0 commit comments

Comments
 (0)