0
votes

My requirement is to get the URI scheme out of the dynamic link URL that has been generated. Even in the firebase sample app, its the deep link url that gets returned and not the URI scheme.

For eg:

When i click on the dynamic link url from email/notes (https://my-app-code.app.goo.gl/value), the callback will be the continueuseractivity function and i use the following block -

BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:incomingUrl completion:^(FIRDynamicLink * _Nullable dynamicLink, NSError * _Nullable error)

to get the url (dynamicLink.url). In this block, i get the deep link url which is this
-> my-web-url (which is a part of the link parameter in the long dynamic link which i have mentioned above).

My actual requirement is to get the URI scheme myappscheme://some-tag/some-tag-id which associated with the URL. How do i get this?

I even tried the below -

FIRDynamicLink *dynamicLink =  [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];

In either cases, I do not get the URI scheme.

Please help.

2

2 Answers

1
votes

What you are trying to do is not currently possible on iOS with Dynamic Links. You are confusing URI scheme (myappscheme://) with URI path (myappscheme://some-tag/some-tag-id).

To my knowledge, Dynamic Links on iOS only support the scheme (via the ius param). This is confusing because Android does support a URI path (via the al param). For iOS, you'll need to do your routing based on the deep link URL.

Alternatively, you could investigate a more robust deep linking platform like Branch.io (full disclosure: I'm on the Branch team). Branch does support custom link parameters containing any data you wish, including a custom URI path.

1
votes

What Alex said is correct. It is not possible, but there is an easy workaround to this.

I appended my desired custom url deep link as a query parameter to the https link url I provided.

So in your case it would look something like this

https://my-app-code.app.goo.gl/?link=https://my-web-url.com/?myCustomSchemeUri%3Dmy-custom-scheme://my-custom-scheme-url&apn=id&isi=android-google-play-id&ibi=ios-bundle-id&ius=ios-custom-app-scheme

When the continueuseractivity callback gets to your app you can retrieve myCustomSchemeUri parameter from the query string and use it as you please.

Something like this:

- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler {

BOOL handled = [[FIRDynamicLinks dynamicLinks]
                handleUniversalLink:userActivity.webpageURL
                completion:^(FIRDynamicLink * _Nullable dynamicLink,
                             NSError * _Nullable error) {
                    // ...
                    NSURL *url = dynamicLink.url;
                    NSString *myUri = [url queryParameterValueWithName:@"customUri"];
                    if (myUri.lenghth > 0){
                        NSURL *myURL = [NSURL URLWithString:myUri];
                        if (myURL != nil){
                            //source application is your bundle id in this case
                            [self application:application openURL:myURL sourceApplication:@"com.yourbundle.id" annotation:@{}];
                        }
                    }
                }];
return handled;
}

And this is the method I wrote as a category of NSURL to retrieve the parameter

- (NSString *)queryParameterValueWithName:(NSString*)name{
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:self
                                            resolvingAgainstBaseURL:NO];
NSArray *queryItems = urlComponents.queryItems;
NSString *param = [self valueForKey:name
                      fromQueryItems:queryItems];
return param;
}

- (NSString *)valueForKey:(NSString *)key
       fromQueryItems:(NSArray *)queryItems
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", key];
NSURLQueryItem *queryItem = [[queryItems
                              filteredArrayUsingPredicate:predicate]
                             firstObject];
return queryItem.value;
}

Maybe this answer is a bit late to you, but I ran into this problem just today. Anyway I hope this helps somebody else out there.

Cheers,

Alessio