Skip to content

Commit

Permalink
[firebase_dynamic_links] Not working on app start (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
jherencia committed Oct 3, 2019
1 parent b97b720 commit 6a3cbbe
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 36 deletions.
4 changes: 4 additions & 0 deletions packages/firebase_dynamic_links/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0+4

* Fixed iOS problems on iOS 12.

## 0.5.0+3

* Don't crash if registrar.activity() is not there.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,48 +123,66 @@ - (BOOL)application:(UIApplication *)application

- (BOOL)checkForDynamicLink:(NSURL *)url {
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
if (dynamicLink) {
if (dynamicLink.url) _initialLink = dynamicLink;
return YES;

if (!dynamicLink) {
dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromUniversalLinkURL:url];
}
return NO;
}

- (BOOL)onLink:(NSUserActivity *)userActivity {
BOOL handled = [[FIRDynamicLinks dynamicLinks]
handleUniversalLink:userActivity.webpageURL
completion:^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
if (error) {
FlutterError *flutterError = getFlutterError(error);
[self.channel invokeMethod:@"onLinkError"
arguments:getDictionaryFromFlutterError(flutterError)];
} else {
NSMutableDictionary *dictionary = getDictionaryFromDynamicLink(dynamicLink);
[self.channel invokeMethod:@"onLinkSuccess" arguments:dictionary];
}
}];
return handled;
}
if (!dynamicLink) {
return NO;
}

- (BOOL)onInitialLink:(NSUserActivity *)userActivity {
BOOL handled = [[FIRDynamicLinks dynamicLinks]
handleUniversalLink:userActivity.webpageURL
completion:^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
if (error) {
self.flutterError = getFlutterError(error);
}
self.initialLink = dynamicLink;
}];
return handled;
if (dynamicLink.url) {
if (_initiated) {
[self.channel invokeMethod:@"onLinkSuccess"
arguments:getDictionaryFromDynamicLink(dynamicLink)];
} else {
_initialLink = dynamicLink;
}
return YES;
}
return NO;
}

- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler {
if (_initiated) {
return [self onLink:userActivity];
}
return [self onInitialLink:userActivity];
restorationHandler:
#if defined(__IPHONE_12_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
#else
(nonnull void (^)(NSArray *_Nullable))restorationHandler {
#endif // __IPHONE_12_0
__block BOOL retried = NO;

id completion = ^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
if (!error && dynamicLink && dynamicLink.url) {
if (_initiated) {
[self.channel invokeMethod:@"onLinkSuccess"
arguments:getDictionaryFromDynamicLink(dynamicLink)];
} else {
_initialLink = dynamicLink;
}
}

// Per Apple Tech Support, a network failure could occur when returning from background on
// iOS 12. https://github.com/AFNetworking/AFNetworking/issues/4279#issuecomment-447108981 So
// we'll retry the request once
if (error && !retried && [NSPOSIXErrorDomain isEqualToString:error.domain] &&
error.code == 53) {
retried = YES;
[[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
completion:completion];
} else if (error) {
FlutterError *flutterError = getFlutterError(error);
[self.channel invokeMethod:@"onLinkError"
arguments:getDictionaryFromFlutterError(flutterError)];
}
};

[[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
completion:completion];

return NO;
}

- (FIRDynamicLinkShortenerCompletion)createShortLinkCompletion:(FlutterResult)result {
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_dynamic_links/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: firebase_dynamic_links
description: Flutter plugin for Google Dynamic Links for Firebase, an app solution for creating
and handling links across multiple platforms.
version: 0.5.0+3
version: 0.5.0+4

author: Flutter Team <[email protected]>
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_dynamic_links
Expand Down

0 comments on commit 6a3cbbe

Please sign in to comment.