React-native-firebase: Dynamic Link on iOS not is receiving parameter from URL

Created on 2 Jul 2018  路  19Comments  路  Source: invertase/react-native-firebase

Hi guys,

I want to ask. The URL receive by .getInitialLink() and .onLink() is different when the dynamic link URL is typed and click.

1st case:

  • Type the link in safari
  • Showed Preview page and I click the open the app button
  • It redirect to my app and the url received is
    https://yummybox.page.link/?link=&apn=...........etc.

2nd case:
I want to try to click the link instead of typing it

  • Open iMessage app, send a link to someelse
  • Click on the bubble and it redirect to the app directly (without going to Safari)
  • But the link received is only https://yummybox.page.link/playlist_example which is the short URL that has no parameters

Can anybody help me how to fix this problem ?

Environment

  1. Application Target Platform: iOS

  2. Development Operating System: macOS High Sierra

  3. Build Tools: VS Code

  4. React Native version: 0.47.2

  5. React Native Firebase Version: 3.2

  6. Firebase Module: Dynamic Link

  7. Are you using typescript? No

iOS Links Stale

Most helpful comment

Hi @FakhruddinAbdi , sorry for late reply

  1. My URL Scheme in info tab is https://yummybox.page.link
  2. This is my AppDelegate.m
[FIROptions defaultOptions].deepLinkURLScheme = @"https://yummybox.page.link";
  1. My associated domains is applinks:yummybox.page.link
  2. I have followed all the documentation

The main issues is iOS have 2 mechanism to handle deep links, with URL scheme dan UniversalLink. Case number 2 is using Universal Link because iMessage supports it. But the URL i received in the app, either with .onLink() or with .getInitialLink() is the short URL. But if the deep link is opened with app that is not supporting Universal Link, iOS will use URL scheme, and it receives the long URL which contains the parameters that required to navigate the app to the content.

All 19 comments

@kevindavee could you please let me what's your following configuration, because i can not get it working ( when click on safari doesn't open on neither simulator nor real device )

if your bundle is : com.example.appName
And Dynamic Links domain in firebase console is appName.page.link

  1. What's your URL scheme in info tab -> URL Types ?
  2. How did you write this line [FIROptions defaultOptions].deepLinkURLScheme = ... in AppDelegate.m` File ?
  3. In Capabilities tab in Associated domain, how did you write Domain field ? ( applinks...)
  4. And finally are the documentation here enough and complete for adding methods in AppDelegate.m file ?

I have detached from expo and started integrating this library, but its about 2, 3 weeks im struggling with this issue and some more

Thanks.

Hi @FakhruddinAbdi , sorry for late reply

  1. My URL Scheme in info tab is https://yummybox.page.link
  2. This is my AppDelegate.m
[FIROptions defaultOptions].deepLinkURLScheme = @"https://yummybox.page.link";
  1. My associated domains is applinks:yummybox.page.link
  2. I have followed all the documentation

The main issues is iOS have 2 mechanism to handle deep links, with URL scheme dan UniversalLink. Case number 2 is using Universal Link because iMessage supports it. But the URL i received in the app, either with .onLink() or with .getInitialLink() is the short URL. But if the deep link is opened with app that is not supporting Universal Link, iOS will use URL scheme, and it receives the long URL which contains the parameters that required to navigate the app to the content.

Hi @kevindavee

Thank you very much for your detailed answer.
This part helped me [FIROptions defaultOptions].deepLinkURLScheme = @"https://yummybox.page.link";

It not well documented , Im going to send a PR

Just one more thing @kevindavee sorry

The dynamic link now open the app, but neither onLink nor getInitialLink, addEventListener('url' doesn't trigger if the app already running.

Just getInitialLink get triggred if we open the app with dynamic link

Do you have solution for it ?

@FakhruddinAbdi I'm facing similar issue.

Using
"react-native-firebase": "^4.1.0"
"react-native": "0.55.4"

We're you able to figure out the solution?

I just missed some functions mentioned in the doc to be added to AppDelegate.m
When i fixed them, it start workgin @surendharreddy

@FakhruddinAbdi can you share those functions or point me to the right place to learn about them?

Here's what I added to my AppDelegate.m

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<NSString *, id> *)options {
    return [[RNFirebaseLinks instance] application:application openURL:url options:options];
}

- (BOOL)application:(UIApplication *)application
        continueUserActivity:(NSUserActivity *)userActivity
        restorationHandler:(void (^)(NSArray *))restorationHandler {
        return [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}
            #import "RNFirebaseNotifications.h"
            #import "RNFirebaseMessaging.h"
            #import "RNFirebaseLinks.h"
            #import <React/RCTLinkingManager.h>
            #import <React/RCTBundleURLProvider.h>
            #import <Firebase.h>
            #import "AppDelegate.h"
            #import "ExpoKit.h"
            #import "EXViewController.h"



            @interface AppDelegate ()

            @property (nonatomic, strong) EXViewController *rootViewController;

            @end

            @implementation AppDelegate

            - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
            {
                [FIROptions defaultOptions].deepLinkURLScheme = @"https://app.page.link";
                [FIRApp configure];
                [RNFirebaseNotifications configure];

                [application registerForRemoteNotifications];
                _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
                _window.backgroundColor = [UIColor whiteColor];
                [[ExpoKit sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
                _rootViewController = [ExpoKit sharedInstance].rootViewController;
                _window.rootViewController = _rootViewController;

                [_window makeKeyAndVisible];

                return YES;
            }

            #pragma mark - Handling URLs

            - (BOOL)application:(UIApplication *)application
                        openURL:(NSURL *)url
                        options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
            {
                return [RCTLinkingManager application:application openURL:url options:options];
            }

            - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * _Nullable))restorationHandler
            {
                return [[ExpoKit sharedInstance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
            }



            #pragma mark - Notifications
            - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
                [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
            }

            - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
            fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
                [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
            }

            - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
                [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
            }


            - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)token
            {
                [[ExpoKit sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:token];
            }

            - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
            {
                [[ExpoKit sharedInstance] application:application didFailToRegisterForRemoteNotificationsWithError:err];
            }
            @end

This is my appdelegate.m file .. FYI i detached from expo

Hi, @kevindavee @FakhruddinAbdi
you should not set
[FIROptions defaultOptions].deepLinkURLScheme = @"https://app.page.link";

you should set deepLinkURLScheme as your bundle id,
base on your case, the correct setting should be :
[FIROptions defaultOptions].deepLinkURLScheme = @"com.example.appName";

also go to Xcode -> Targets -> URL types -> set a new url type
identifier: Bundle ID(or any unique value)
URL Schemes: com.example.appName(you bundle id)

Got it working by following this guide https://facebook.github.io/react-native/docs/linking#handling-deep-links

Hello 馃憢, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

Hello - is this something that was ever fixed? I successfully integrated dynamic links - the app opens, I receive the resolved URL from onLink however the URL does not include any of the query parameters that are present on the dynamic link.

@mtford90 same here, can not get any param. do u find any solution for this ?

created a dynamic link by API not by Firebase console and add isi into the link solved my problem

@thanh90 do you have a complete example of the code (or links) you have working now? It could help a lot of people in the future - this is a difficult thing for people to get working, based on issue counts. Thanks!

const link = 
        new firebase.links.DynamicLink("https://xxx.com/foo/bar/", "https://xxx.page.link")
            .android.setPackageName("com.xxx.android")
            .ios.setBundleId("com.xxx.ios")
            .ios.setAppStoreId("144xxxx310"); 

        firebase.links()
            .createDynamicLink(link)
            .then((url) => {
                console.log('generated dynamic link', decodeURIComponent(url));
                Linking.openURL(decodeURIComponent(url));
            }).catch(err => console.log(err));

You have to create a URL prefix 'https://xxx.page.link' on Firebase Console

fantastic, thank you!

Was this page helpful?
0 / 5 - 0 ratings