Skip to content

[firebase_dynamic_links] make sure the initial link resolves #2580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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+13

- Fix for possible race condition in `getInitialLink` (iOS only).

## 0.5.0+12

* Fix for missing UserAgent.h compilation failures.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
@interface FLTFirebaseDynamicLinksPlugin ()
@property(nonatomic, retain) FlutterMethodChannel *channel;
@property(nonatomic, retain) FIRDynamicLink *initialLink;
@property(nonatomic, assign) BOOL isResolvingInitialLink;
@property(nonatomic, retain) FlutterError *flutterError;
@property(nonatomic) BOOL initiated;
@end
Expand All @@ -67,6 +68,7 @@ - (instancetype)initWithChannel:(FlutterMethodChannel *)channel {
self = [super init];
if (self) {
_initiated = NO;
_isResolvingInitialLink = NO;
_channel = channel;
if (![FIRApp appNamed:@"__FIRAPP_DEFAULT"]) {
NSLog(@"Configuring the default Firebase app...");
Expand All @@ -92,12 +94,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
completion:[self createShortLinkCompletion:result]];
} else if ([@"FirebaseDynamicLinks#getInitialLink" isEqualToString:call.method]) {
_initiated = YES;
NSMutableDictionary *dict = [self getInitialLink];
if (dict == nil && self.flutterError) {
result(self.flutterError);
} else {
result(dict);
}
[self continueGetInitialLinkWithResult:result];
} else if ([@"FirebaseDynamicLinks#getDynamicLink" isEqualToString:call.method]) {
NSURL *shortLink = [NSURL URLWithString:call.arguments[@"url"]];
FIRDynamicLinkUniversalLinkHandler completion =
Expand All @@ -114,6 +111,21 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
}
}

- (void)continueGetInitialLinkWithResult:(FlutterResult)result {
if (_isResolvingInitialLink == YES) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self continueGetInitialLinkWithResult:result];
});
return;
}
NSMutableDictionary *dict = [self getInitialLink];
if (dict == nil && self.flutterError) {
result(self.flutterError);
} else {
result(dict);
}
}

- (NSMutableDictionary *)getInitialLink {
return getDictionaryFromDynamicLink(_initialLink);
}
Expand Down Expand Up @@ -157,13 +169,15 @@ - (BOOL)onLink:(NSUserActivity *)userActivity {
}

- (BOOL)onInitialLink:(NSUserActivity *)userActivity {
self.isResolvingInitialLink = YES;
BOOL handled = [[FIRDynamicLinks dynamicLinks]
handleUniversalLink:userActivity.webpageURL
completion:^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
if (error) {
self.flutterError = getFlutterError(error);
}
self.initialLink = dynamicLink;
self.isResolvingInitialLink = NO;
}];
return handled;
}
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+12
version: 0.5.0+13
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_dynamic_links

dependencies:
Expand Down