React-native-firebase: Dynamic links on IOS not working

Created on 12 Apr 2020  ยท  48Comments  ยท  Source: invertase/react-native-firebase


Issue



Describe your issue here

Hey, I have been trying to use dynamic links in my app and ran into an issue on IOS where the dynamicLinks().getInitialLink() always returns null and the dynamicLinks().onLink() is not called upon entering the app from dynamic link

Project Files






Javascript

Click To Expand

#### `package.json`:

  "dependencies": {
    "@react-native-community/async-storage": "1.6.2",
    "@react-native-community/google-signin": "4.0.0",
    "@react-native-community/masked-view": "0.1.6",
    "@react-native-community/netinfo": "4.4.0",
    "@react-native-firebase/app": "6.3.4",
    "@react-native-firebase/crashlytics": "6.3.4",
    "@react-native-firebase/dynamic-links": "6.3.4",
    "@react-native-firebase/messaging": "6.3.4",
    "amplitude-js": "5.8.0",
    "lottie-react-native": "3.3.2",
    "mobx": "5.15.2",
    "mobx-react": "6.1.5",
    "moment": "2.24.0",
    "react": "16.9.0",
    "react-native": "0.61.2",
    "react-native-agora": "2.9.1-alpha.3",
    "react-native-appsflyer": "5.1.3",
    "react-native-deep-link": "0.2.9",
    "react-native-device-info": "5.2.1",
    "react-native-gesture-handler": "1.5.3",
    "react-native-haptic-feedback": "1.8.2",
    "react-native-home-indicator": "0.2.5",
    "react-native-keep-awake": "4.0.0",
    "react-native-linear-gradient": "2.5.6",
    "react-native-onesignal": "3.4.2",
    "react-native-orientation": "3.1.3",
    "react-native-reanimated": "1.7.0",
    "react-native-safe-area-context": "0.6.2",
    "react-native-screens": "2.0.0-alpha.26",
    "react-native-video": "5.0.2",
    "react-native-webview": "7.4.2",
    "react-navigation": "4.0.10",
    "react-navigation-stack": "1.10.3",
    "react-navigation-tabs": "2.7.0",
    "react-navigation-transitions": "1.0.12",
    "self-adjusting-interval": "1.0.0"
  },
  "devDependencies": {
    "@babel/core": "7.6.4",
    "@babel/plugin-proposal-decorators": "7.8.3",
    "@babel/runtime": "7.6.3",
    "@react-native-community/eslint-config": "0.0.3",
    "babel-jest": "24.9.0",
    "eslint": "6.5.1",
    "jest": "24.9.0",
    "metro-react-native-babel-preset": "0.51.1",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  },
  "rnpm": {
    "assets": [
      "./assets/fonts/"
    ]
  }
}
#### `firebase.json` for react-native-firebase v6:
# N/A
### iOS
Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like:

platform :ios, '10.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'jumper' do
  # Pods for jumper
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  pod 'react-native-orientation', :path => '../node_modules/react-native-orientation'

  pod 'react-native-webview', :path => '../node_modules/react-native-webview'

  pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'


  pod 'react-native-onesignal', :path => '../node_modules/react-native-onesignal'

  pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'

  pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

  pod 'react-native-home-indicator', :path => '../node_modules/react-native-home-indicator'

  pod 'RNReactNativeHapticFeedback', :path => '../node_modules/react-native-haptic-feedback'

  pod 'lottie-ios', :path => '../node_modules/lottie-ios'

  pod 'lottie-react-native', :path => '../node_modules/lottie-react-native'

  pod 'react-native-keep-awake', :path => '../node_modules/react-native-keep-awake'


  pod 'react-native-video', :path => '../node_modules/react-native-video'

  pod 'BVLinearGradient', :path => '../node_modules/react-native-linear-gradient'

  pod 'Firebase/Core'
  pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app'
  pod 'Firebase/Analytics'
  pod 'RNGoogleSignin', :path => '../node_modules/@react-native-community/google-signin'
  pod 'RNFBCrashlytics', :path => '../node_modules/@react-native-firebase/crashlytics'
  pod 'RNFBMessaging', :path => '../node_modules/@react-native-firebase/messaging'
  pod 'RNFBDynamicLinks', :path => '../node_modules/@react-native-firebase/dynamic-links'
  pod 'react-native-agora', :path => '../node_modules/react-native-agora'

  target 'jumperTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end

target 'jumper-tvOS' do
  # Pods for jumper-tvOS

  target 'jumper-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

target 'OneSignalNotificationServiceExtension' do
  pod 'OneSignal', '>= 2.9.3', '< 3.0'
end
#### `AppDelegate.m`:
/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import "AppDelegate.h"
#import "Orientation.h"
#import <RNHomeIndicator.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTLinkingManager.h>
#import <React/RCTRootView.h>
@import UIKit;
@import Firebase;
@import AppsFlyerLib;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [application registerForRemoteNotifications];
  [FIRApp configure];
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"jumper"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [HomeIndicatorViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [Orientation getOrientation];
}

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
  [[AppsFlyerTracker sharedTracker] registerUninstall:deviceToken];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
  return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}
@end


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`:

// N/A
#### `android/app/build.gradle`:
// N/A
#### `android/settings.gradle`:
// N/A
#### `MainApplication.java`:
// N/A
#### `AndroidManifest.xml`:
<!-- N/A -->


Environment

Click To Expand

**`react-native info` output:**

System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i7-2677M CPU @ 1.80GHz
    Memory: 19.49 MB / 4.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.13.0 - /usr/local/bin/node
    npm: 6.12.0 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
  IDEs:
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.2 => 0.61.2 
  npmGlobalPackages:
    react-native-cli: 2.0.1
- **Platform that you're experiencing the issue on**: - [x] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - 6.3.4 - **`Firebase` module(s) you're using that has the issue:** - dynamic links - **Are you using `TypeScript`?** - No




Needs Repro Links Docs Stale >= 6

Most helpful comment

Ok I've managed to get this working by simply adding FirebaseDynamicLinksCustomDomains to my Info.plist (as suggested by others above ๐Ÿ‘).

Works on Debug and Release builds thankfully.

https://firebase.google.com/docs/dynamic-links/ios/receive#open-dynamic-links-in-your-app

<key>FirebaseDynamicLinksCustomDomains</key>
<array>
  <string>https://mycustomdomain.com/</string>
</array>

Note, I'm still seeing the "A server with the specified hostname could not be found." error in my Xcode console but it doesn't appear to affect the dynamic link going through.

All 48 comments

I'm having the same issue, in addition, I'm not using a custom domain and in android works correctly.

+1.

To work around this issue I'm using Linking package from RN:

   if (Platform.OS === 'ios') {
      url = await Linking.getInitialURL();
    } else {
      const res = await dynamicLinks().getInitialLink();
      if (res) {
        url = res.url;
      }
    }

@TalEliel @MarcoF09 @ahanusek
Hey! I'm having similar issues as well. Where did you guys find information about configuring AppDelegate.m to allow dynamic links to work (back/foreground)?

I spent a day looking for those without luck. And it seems what needs to be added to AppDelegate.m on v5 is different from v6... right?

I appreciate in advance if you guys could point me to some documentation about that.

I'm in the same boat, why do the v6 docs not cover the necessary configurations for RNFB Dynamic Links in the AppDelegate.m?

Here's a snippet of what I found, but it only sometimes works:

AppDelegate.m

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}

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

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

I try to handle a login link for sendSignInLinkToEmail in my Login component:

useEffect(() => {
    return dynamicLinks().onLink(async link => {
      if (auth().isSignInWithEmailLink(link.url)) {
        if (!email) {
          // TODO: If no email, have user input
          return
        }

        try {
          await auth().signInWithEmailLink(email, link.url)
        } catch (e) {
          console.error(e)
        }
      } else {
        // Not a dynamic link for auth, handle with router
      }
    })
  }, [email])

The issue this only sometimes gets triggered. I can't figure out why, maybe it's a dev only thing, but it's frustrating that the docs don't clearly say what the setup ought to be so I can troubleshoot just my code instead

PRs always welcome, the docs all have an edit button at top right

@russellwheatley only a comment, in my case occurs also in version 5.6.0.

I am having the same issue, someone can address this issue?

Hey @TalEliel, could you please confirm that you have actually added a URL type? Effectively, you need to add your Bundle ID to the URL Schemes property, and call the Identifier property whatever name you want (I've called mine "Bundle ID").
Screenshot 2020-04-22 at 11 22 40

If I did not set this, then the returned object from the dynamicLinks().getInitialLink() call would be null.

Hey @russellwheatley , yes i did add a utl type with the bundle identifie.
I just believe that there shoulb be some code to be implemented in the appDelegate.m file that is nowehre to be found in the documentaion and every code snipet i found online didn't work either

Interesting. I created a fresh RN project, the only code I added to my appDelegate.m was the Firebase Config code you already have in your appDelegate.m:
Screenshot 2020-04-22 at 11 50 05

Do you mind if I see your GoogleServices-info.plist, please @TalEliel ?

@russellwheatley sure. this is the file.
and the strings are the actual data i replaced them for privacy
Screenshot_1

do you mind pasting that into the comment box, please?

@russellwheatley

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd%22%3E
<plist version="1.0">
<dict>
    <key>CLIENT_ID</key>
    <string>CLIENT_ID</string>
    <key>REVERSED_CLIENT_ID</key>
    <string>REVERSED_CLIENT_ID</string>
    <key>API_KEY</key>
    <string>API_KEY</string>
    <key>GCM_SENDER_ID</key>
    <string>GCM_SENDER_ID</string>
    <key>PLIST_VERSION</key>
    <string>PLIST_VERSION</string>
    <key>BUNDLE_ID</key>
    <string>BUNDLE_IDr</string>
    <key>PROJECT_ID</key>
    <string>PROJECT_ID</string>
    <key>STORAGE_BUCKET</key>
    <string>STORAGE_BUCKET</string>
    <key>IS_ADS_ENABLED</key>
    <false></false>
    <key>IS_ANALYTICS_ENABLED</key>
    <false></false>
    <key>IS_APPINVITE_ENABLED</key>
    <true></true>
    <key>IS_GCM_ENABLED</key>
    <true></true>
    <key>IS_SIGNIN_ENABLED</key>
    <true></true>
    <key>GOOGLE_APP_ID</key>
    <string>GOOGLE_APP_ID</string>
    <key>DATABASE_URL</key>
    <string>DATABASE_URL</string>
</dict>
</plist>

Hmmm, there is nothing out of the ordinary with your GoogleServices-info.plist. Unfortunately, I cannot debug if I cannot recreate. Do you mind creating a reproduction repository of this issue, please?

I'm also having problems with Dynamic Links on iOS. Both onLink and getInitialLink return null.
I can see in XCode debug console:

2020-04-23 16:11:08.614347+0200 App[52231:1275885] Task <3E55F296-87F6-43FE-BB40-46314F6FF585>.<5> finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={NSUnderlyingError=0x600001d29650 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, NSErrorFailingURLStringKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=<some_key>, NSErrorFailingURLKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=<some_key>, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSLocalizedDescription=A server with the specified hostname could not be found.}

Not sure if this is related? I see a similar report in firebase-ios-sdk

@wincjh everyone gets email and notifications when you do that +1 thing. Just use a reaction on the issue, or fill your comment box with either new information worthy of the attention you take from all participants, or a link to the PR you made that will fix it ๐Ÿ’ช

The same issue with me. Is there any update for this?

same problem.

Same issue. I was able to see the link with using React Native's Linking module, however it only interprets shortened URL's via the "Open link in app?" interstitial. Clicking the link from my Messages app outputs only the already shortened URL.

Also seeing this issue here, could it be related?

https://github.com/facebook/react-native/issues/24429

I had the same issue initially.
For me getInitialLink also sometimes did return null but then onLink returns the correct data.
This is my implementation if anybody wants to try it (top of App.js):

import { useEffect } from 'react';
import dynamicLinks from '@react-native-firebase/dynamic-links';

const useSetupDynamicLinks = () => {
  const handleDynamicLink = async (link) => {
    if (link && link.url) {
      // do something with it
    }
  };

  useEffect(() => {
    // for background/quit events
    const link = dynamicLinks().getInitialLink();
    handleDynamicLink(link);

    // for foreground events
    const unsubscribeLinkListener = dynamicLinks().onLink(handleDynamicLink);
    return () => unsubscribeLinkListener();
  }, []);
};

export default useSetupDynamicLinks;

Hey @bobinrinder
Thanks for sharing that! Do you mind sharing also what you have in your AppDelegate.m?

GULAppDelegateSwizzler seems to call RNFBDynamicLinksAppDelegateInterceptor with nil values.

So

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation

openURL is nil, initialLinkUrl is not setup and remains nil/null.

image

I'm seeing this behavior on my app as well. Any additional context that would be helpful?

My issues appeared to be related to using a custom domain and needing to set FirebaseDynamicLinksCustomDomains as documented in the official FB docs: https://firebase.google.com/docs/dynamic-links/ios/receive#objective-c_3

EDIT: Scratch that... it was working in my Debug build but doesn't work on a cold app-start in my release version

Background

I'm experiencing this issue too. Specifically, the Dynamic Link from a "passwordless email authentication" email, when clicked in Apple Mail, has failed to open my app, and has instead opened iOS Safari. This has been the case for 3 out of my 8 testers, which is a really awful failure rate. They're all on iOS 13.

@russellwheatley Could I please have a basic sanity check of whether my AppDelegate.m has been implemented correctly to expect that Dynamic Links should work?

I've following the latest Dynamic Links documentation for React Native Firebase (which, incidentally, have greatly improved in the last weeks โ€“ thank you!). It doesn't mention anything about how we should set up AppDelegate.m, however.

Firebase Dynamic Links for iOS official docs

For reference (please nobody copy this without reading on), in Google's Firebase Dynamic Links docs for iOS, they show the following:

- (BOOL)application:(UIApplication *)app
            openURL:(NSURL *)url
            options:(NSDictionary<NSString *, id> *)options {
  return [self application:app
                   openURL:url
         sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
  FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];

  if (dynamicLink) {
    if (dynamicLink.url) {
      // Handle the deep link. For example, show the deep-linked content,
      // apply a promotional offer to the user's account or show customized onboarding view.
      // ...
    } else {
      // Dynamic link has empty deep link. This situation will happens if
      // Firebase Dynamic Links iOS SDK tried to retrieve pending dynamic link,
      // but pending link is not available for this device/App combination.
      // At this point you may display default onboarding view.
    }
    return YES;
  }
  return NO;
}

React Native Dynamic Links

I notice that in React Native Firebase, however, some magic is going on. The library implements RNFBDynamicLinksAppDelegateInterceptor, which swizzles the app's AppDelegate.

I have no clue exactly what the swizzling is doing behind the scenes, and it would be great if it were documented!

My own code

My guess from debugging, though, is that RNFBDynamicLinksAppDelegateInterceptor runs before our own AppDelegate runs, and therefore when using React Native Firebase, we don't need to write anything in openURL:options:completionHandler: at all.

Nonetheless, I've put a guard in to make sure that my app (which also handles URLs passed to it from an Action Extension) doesn't accidentally handle a URL that has already been handled. Could you please clarify whether this guard is redundant @russellwheatley.

openURL:options:completionHandler:

// For an app called Sundial, with the bundle ID: "com.sundial.app"
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  if(url){
    if([url.absoluteString hasPrefix:@"com.sundial.app://google"]){
      RCTLogInfo(@"This is a Firebase Dynamic Link! Should have been handled by RNFBDynamicLinksAppDelegateInterceptor already.");
      return YES;
    }

    if([url.absoluteString hasPrefix:@"com.sundial.app://sundial/openURL/"]){
      RCTLogInfo(@"Our Action Extension (e.g. 'Open in Sundial') passed us a link! TODO: handle.");
      return YES;
    }
  }
  return NO;
}

application:didFinishLaunchingWithOptions:

For my application:didFinishLaunchingWithOptions:, I've written the following:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // As per: https://rnfirebase.io/#configure-firebase-with-ios-credentials
  if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }

 // Strictly set up RCTBridge, etc. only AFTER configuring FIRApp!

  // ...

  // I was advised from somewhere to add in this line, possibly from the React Native
  // Firebase Issues. Or maybe it was recommended by some other unrelated library.
  // I've long since forgotten.
  //
  // Either way, could you please clarify whether this line should be removed or not,
  // given that React Native Firebase has this mysterious AppDelegate swizzling?
  [super application:application didFinishLaunchingWithOptions:launchOptions];

  return YES;
}

Thank you very much for any help! Happy to provide more details.

+1.

To work around this issue I'm using Linking package from RN:

   if (Platform.OS === 'ios') {
      url = await Linking.getInitialURL();
    } else {
      const res = await dynamicLinks().getInitialLink();
      if (res) {
        url = res.url;
      }
    }

@ahanusek Do the Dynamic links work for iOS in all cases when you use Linking, where they'd been failing before by using React Native Firebase Dynamic Links?

Has anyone faced the issues when it says:

NSErrorFailingURLStringKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=AIzaSyC4MXdWE2_EwJQXU1kC8hZZ7Vm1XOvCufA,
NSErrorFailingURLKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=AIzaSyC4MXdWE2_EwJQXU1kC8hZZ7Vm1XOvCufA

The whole error:

Task <401C75F4-F8F0-47F4-A92D-7778E3F49A72>.
<5> finished with error [-1003]
Error Domain=NSURLErrorDomain Code=-1003
"A server with the specified hostname could not be found."
UserInfo={NSUnderlyingError=0x600002cdc420
{Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)"
UserInfo={
_kCFStreamErrorCodeKey=8,
_kCFStreamErrorDomainKey=12}},
NSErrorFailingURLStringKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=AIzaSyC4MXdWE2_EwJQXU1kC8hZZ7Vm1XOvCufA,
NSErrorFailingURLKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=AIzaSyC4MXdWE2_EwJQXU1kC8hZZ7Vm1XOvCufA,
_kCFStreamErrorDomainKey=12,
_kCFStreamErrorCodeKey=8,
NSLocalizedDescription=A server with the specified hostname could not be found.}

๐Ÿ™

@alex-mironov if I recall correctly someone mentioned it in another issue and it was their project setup was incomplete. https://github.com/invertase/react-native-firebase/issues/3755#issuecomment-640599449

@mikehardy thanks, from what I can tell setup is fine, the link is opened. The problem I'm seeing, is that this failure on start increases startup time significantly. I'm trying to find a way to postpone deeplinks initialization, but it seems to be native part, which I cannot influence much from the JS...

Here is related issue btw https://github.com/firebase/firebase-ios-sdk/issues/5032

How unfortunate. A quick read of that issue (thanks for the link!) shows this as prior art: https://github.com/googleapis/google-api-dotnet-client/issues/1186#issuecomment-382863980 and indicating that the hostname is either misconfigured or as a recent PR indicates, they need to handle it better

In the meantime, there is nothing as nifty that I have seen as patch-package for cocoapods, but I wonder if you could hand-hack https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseDynamicLinks/Sources/FIRDynamicLinkNetworking.m#L36 to be v4 in both cases if it would work :thinking: for now

So after reading the entire thread we're still nowhere near to understanding what configuration is actually required for AppDelegate.m. All I can say for certain is that in a completely fresh project, the current docs for Dynamic Links at rnfirebase.io are inconclusive and do not trigger events when links are opened.

Hitting this issue also on iOS. Followed the guide here https://rnfirebase.io/dynamic-links/usage#listening-for-dynamic-links. App opens correctly when clicking on the dynamic link but dynamicLinks().getInitialLink() and dynamicLinks().onLink() aren't working?

Oh apologies, it seems like its actually an issue with the firebase sdk itself (as mentioned by others above). https://github.com/firebase/firebase-ios-sdk/issues/5032

Check Xcode and I'm getting the same error:

Task <0B09E54B-6A0D-46EF-8410-2DE8B08B2313>.<3> finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={NSUnderlyingError=0x282c99ce0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, NSErrorFailingURLStringKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=AIzaSyAlb7tK2gxW34JefQLI7uEm5j22ICCiILk, NSErrorFailingURLKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=AIzaSyAlb7tK2gxW34JefQLI7uEm5j22ICCiILk, _kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, NSLocalizedDescription=A server with the specified hostname could not be found.}

@mrbrentkelly reach right into that cocoapod and hack out the ipv6 thing. I bet it works for you. If it does, then I would write a tiny idempotent change in ruby in your podfile as a post_install hook https://guides.cocoapods.org/syntax/podfile.html#post_install

That hook should take the patch you generate from running patch after making your change, and should attempt to apply it (a la the javascript-level patch-package)

You'll have reproducibly applied your change then and you can maybe move forward until the upstream issue is resolved

There are many in this position, any report you had of success with this style would probably be met with a lot of thanks

Thanks @mikehardy ๐Ÿ‘. I just removed what I thought to be the code ipv6 code in FirebaseDynamicLinks Pod. The error goes away from the console but dynamicLinks().getInitialLink() and dynamicLinks().onLink() still aren't getting called unfortunately ๐Ÿค”

Ok I've managed to get this working by simply adding FirebaseDynamicLinksCustomDomains to my Info.plist (as suggested by others above ๐Ÿ‘).

Works on Debug and Release builds thankfully.

https://firebase.google.com/docs/dynamic-links/ios/receive#open-dynamic-links-in-your-app

<key>FirebaseDynamicLinksCustomDomains</key>
<array>
  <string>https://mycustomdomain.com/</string>
</array>

Note, I'm still seeing the "A server with the specified hostname could not be found." error in my Xcode console but it doesn't appear to affect the dynamic link going through.

@mrbrentkelly I had a similar experience to you where adding the plist key/value let my links staart working as expected. However I quickly realized that the flow was pretty flaky. I would say I had about 50/50 success/failure when using the link through an app install

I fixed with this simple line in the openURL delegate in AppDelegate.m:
[[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];

And my final code with Firebase Dynamic Links + React Native Linking:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  // fix Firebase Dynamic Links
  [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];

  // Deep Links required: https://reactnative.dev/docs/linking#enabling-deep-links
  return [RCTLinkingManager application:app openURL:url options:options];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
  // Deep Links required: https://reactnative.dev/docs/linking#enabling-deep-links
  return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}

Versions:

react-native: 0.61.5
@react-native-firebase/dynamic-links: 7.2.0

@RodolfoGS something went wrong with AppDelegate swizzling for you, that should not be necessary and is not documented because it is not supposed to be necessary:

https://github.com/invertase/react-native-firebase/blob/a6dc460955bf5d92490cb8b285b4f68e9c10b832/packages/dynamic-links/ios/RNFBDynamicLinks/RNFBDynamicLinksAppDelegateInterceptor.m#L24-L35

Haven't had problems with current lib version, except with Detox e2e tests using device.openURL().
@RodolfoGS 's snippet fixed it for me.

I thought RCTLinkingManager implementation was not needed when using Firebase Dynamic Links, but apparently it is?

I was getting very inconsistent results when I set up the onLink listener before calling getInitialLink. Sometimes it would trigger the listener first and getInitialLink would be null. YMMV.

Now considering just using the standard React Native Linking lib with Linking.getInitialURL() and Linking.addEventListener('url', handler) combined with the new dynamicLinks.resolveLink() to get the best of both worlds. Will I miss anything from the Dynamic Links counterparts?

Hey guys, I really don't know if it matters or not but have you tried setting FIROptions before FIRApp configure like so:

[FIROptions defaultOptions].deepLinkURLScheme = @"deep_link_alias_name_or_whatever";
[FIRApp configure];

ps. I'm using v5.6.0

from google docs you need to add that FirebaseDynamicLinksCustomDomains in info.plist .
iOS only: In your Xcode project's Info.plist file, create a key called FirebaseDynamicLinksCustomDomains and set it to your app's Dynamic Links URL prefixes. For example:

<key>FirebaseDynamicLinksCustomDomains</key>
<array>
  <string>https://example.com/link</string>
  <string>https://example.com/promos</string>
</array>

https://firebase.google.com/docs/dynamic-links/custom-domains#using_your_web_domain_for

Hello ๐Ÿ‘‹, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days 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.

I had the same problem on iOS. After spending hours debugging firebase source code, i found out that the problem was with the deeplink part of dynamic link. I have not encoded all of the query params

Initial link - https://my.custom.domain/?link=https://myapp.com/open?param1=value1&param2=value2&apn=com.myapp&ibi=com.my.app&isi=0000000000&ofl=https://app.domain/getapp

How deeplink part should look like - link%3Dhttps%3A%2F%2Ftellapp.com%2Fopen%3Fparam1%3Dvalue1%26param2%3Dvalue2

The one i had - link%3Dhttps%3A%2F%2Ftellapp.com%2Fopen%3Fparam1%3Dvalue1%26param2=value2

The final dynamic link should look like this - https://my.custom.domain/?link%3Dhttps%3A%2F%2Ftellapp.com%2Fopen%3Fparam1%3Dvalue1%26param2%3Dvalue2&apn=com.myapp&ibi=com.my.app&isi=0000000000&ofl=https://app.domain/getapp

I hope that it will help someone =)

I had the same problem on iOS. After spending hours debugging firebase source code, i found out that the problem was with the deeplink part of dynamic link. I have not encoded all of the query params

Initial link - https://my.custom.domain/?link=https://myapp.com/open?param1=value1&param2=value2&apn=com.myapp&ibi=com.my.app&isi=0000000000&ofl=https://app.domain/getapp

How deeplink part should look like - link%3Dhttps%3A%2F%2Ftellapp.com%2Fopen%3Fparam1%3Dvalue1%26param2%3Dvalue2

The one i had - link%3Dhttps%3A%2F%2Ftellapp.com%2Fopen%3Fparam1%3Dvalue1%26param2=value2

The final dynamic link should look like this - https://my.custom.domain/?link%3Dhttps%3A%2F%2Ftellapp.com%2Fopen%3Fparam1%3Dvalue1%26param2%3Dvalue2&apn=com.myapp&ibi=com.my.app&isi=0000000000&ofl=https://app.domain/getapp

I hope that it will help someone =)

@wanderSX Tried the above solutions and also which you shared nothing works in the installation process when the user first click on Dynamic link and install the app.

Was this page helpful?
0 / 5 - 0 ratings