【问题标题】:Firebase dynamic links are null after new install, but work well when installedFirebase 动态链接在新安装后为空,但安装后运行良好
【发布时间】:2021-11-11 18:55:55
【问题描述】:

安装应用后,深度链接配置适用于 iOS 和 Android。域https://friends.unblnd.com/dynamic 的配置文件似乎没问题。

但安装后无法识别深层链接。

所以监听器工作得很好,但是从后台启动时获取初始 url 不是。

  • Logcat:Pixel 2,模拟器

// 当 app 被安装 我们得到预期的行为

I/ReactNativeJS: 'FIREBASE LISTENING:', { utmParameters: 
       { utm_source: 'firebase',
         utm_medium: 'dynamic_link',
         utm_campaign: 'Online Cooking | UNBLND' },
      minimumAppVersion: null,
      url: 'https://unblnd.com/invite/group/eyJpdiI6IkNyMSsxTnJRWHJyQys3ZWZZd0R5Tnc9PSIsInZhbHVlIjoiRlFaQ2o3R0F0cnRpLzFvYzZ3WC9tQT09IiwibWFjIjoiOWFhZmIzZjk2MjM1MGQ5YTU5Y2M5YjBmOTIwNTdjODZkMzE3ZGY4ZTMyOTZmOTNhY2ZhZGM5NGNjNzc1NDEzYiJ9' }

//当点击Firebase动态链接(friends.unblnd.com/dynamic/aF8A),应用需要安装,安装后深层链接不找到

I/ReactNativeJS: 'FIREBASE URL:', null
  • React Native:配置

深度链接在 React Navigation v5 中配置。添加了获取初始url的自定义函数和订阅函数,以下const linking作为属性添加<NavigationContainer linking={linking} ...>

  const linking = {
    prefixes: [
      'https://friends.unblnd.com/dynamic/',
      ...
    ],
    config: deepLinksConf,
    // Custom function to get the URL which was used to open the app
    async getInitialURL() {
      // First, you may want to do the default deep link handling
      // Check if app was opened from a deep link
      const url = await Linking.getInitialURL();
      console.log('FOUND URL:', url);

      if (url != null) {
        return url;
      }

      // Next, you would need to get the initial URL from your third-party integration
      // It depends on the third-party SDK you use
      const link = await dynamicLinks().getInitialLink();
      for (var i = 0; i < 20; i++) {
        setTimeout(async function () {
          console.log('FIREBASE:', i, await dynamicLinks().getInitialLink());
        }, 500 * i);
      }
      console.log('FIREBASE URL:', url);

      return link.url;
    },
    // Custom function to subscribe to incoming links
    subscribe(listener) {
      // First, you may want to do the default deep link handling
      const onReceiveURL = ({url}) => {
        console.log(url);
        ... handle url
        listener(url);
      };

      // Listen to incoming links from deep linking
      Linking.addEventListener('url', onReceiveURL);

      const unsubscribeToDynamicLinks = dynamicLinks().onLink((link) => {
        console.log('FIREBASE LISTENING:', link);
        onReceiveURL(link);
      });

      return () => {
        // Clean up the event listeners
        unsubscribeToDynamicLinks();
        Linking.removeEventListener('url', onReceiveURL);
      };
    },
  };

- 配置:Firebase 动态链接

在您的 Android 应用中打开深层链接 [APP]

如果您的应用尚未安装,请将用户发送至 您的应用的 Google Play 页面

- React Native:信息

System:
    OS: macOS 11.5.2
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 43.73 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 6.14.15 - ~/htdocs/unblnd_app/node_modules/.bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2
      System Images: android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.2 AI-202.7660.26.42.7486908
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_265 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.2 => 0.64.2 
    react-native-macos: Not Found
    @react-native-firebase/analytics: "^12.8.0",
    @react-native-firebase/app: "^12.8.0",
    @react-native-firebase/dynamic-links: "^12.8.0",
    @react-navigation/native: "^5.9.4",
    @react-navigation/stack: "^5.14.5",

如何让它按预期工作? 现在,它与内部 url 方案具有相同的行为......也许需要尝试 Branch.io?

【问题讨论】:

    标签: javascript react-native react-navigation deep-linking firebase-dynamic-links


    【解决方案1】:

    我们开始使用 branch.io,它运行良好: npm package - react native branch

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多