“初始化分支时出现问题。任务超时。”是什么意思?来自 Branch.io 的意思是?

问题描述 投票:0回答:1

我有一个

react-native
应用程序 (Expo),它使用 Branch.io 的 RN SDK 进行深度链接和延迟深度链接。

仅在 Android 上,

branch.subscribe()
方法在应用程序启动时会遇到此错误:

Trouble initializing Branch. Task exceeded timeout.

这是什么意思以及如何防止该错误?我无法找到任何有关此错误的 Branch.io 文档。

我在 Android 上遇到延迟深层链接问题,我想知道此错误是否可能相关,即使它来自代码的不同部分。

Linking
react-navigation
的配置:

const config = {
  screens: {
    'reset-password': 'reset-password',
    registration: 'registration',
    'not-found': '*',
  },
};

const linking: LinkingOptions<RootStackParamList> = {
  prefixes: [prefix],
  config,
  // This runs whenever the app opens from a closed state
  getInitialURL: async () => {
    const recentParams = await branch.getLatestReferringParams();
    Sentry.addBreadcrumb({
      message: 'getInitialURL recentParams',
      data: recentParams,
    });

    if (
      recentParams['+clicked_branch_link'] &&
      recentParams['$deeplink_path']
    ) {
      return prependSchema(recentParams['$deeplink_path'] as string);
    }
    // await SecureStore.deleteItemAsync(SecureStoreKeys.installParamsUsed);

    // The params from the first Branch deep link tapped for this app
    // These are constant, and can only be reset by uninstalling the app
    // So we only use them when: a) the app is opening from a closed state;
    // b) there are no more-recently-tapped deep links; and c) the user is
    // opening the app within 10 minutes of the initial deep link tap
    const installParams = await branch.getFirstReferringParams();
    Sentry.addBreadcrumb({
      message: 'getInitialURL installParams',
      data: installParams,
    });

    if (
      installParams['+clicked_branch_link'] &&
      installParams['+is_first_session']
    ) {
      // Only use installParams if clicked within 10 minutes
      const clickTimestamp = installParams['+click_timestamp'];
      if (clickTimestamp) {
        const tenMinutes = 1000 * 60 * 10;
        const now = Date.now();
        const clickTimestampMillis = clickTimestamp * 1000;

        if (now - clickTimestampMillis < tenMinutes) {
          if (installParams['$deeplink_path']) {
            return prependSchema(installParams['$deeplink_path'] as string);
          }
        } else {
          Sentry.addBreadcrumb({
            message: 'getInitialURL Ignoring stale installParams',
            data: installParams,
          });
        }
      }
    }
    const url = await Linking.getInitialURL();
    Sentry.addBreadcrumb({
      message: 'getInitialURL Linking.getInitialURL()',
      data: { url },
    });

    return url;
  },
  // Use listener to pass in deep links that come in when app is in background state
  // react-native-branch will pick up all deep links, including non-Branch deep links
  subscribe(listener) {
    // Use this listener to handle non-Branch deep links
    // The Branch listener (below) _can_ handle non-Branch deep links,
    // but the Branch SDK can also have errors, so using this listener is the
    // safer option
    const linkingSub = Linking.addEventListener('url', (event) => {
      Sentry.addBreadcrumb({
        message: 'Linking url event',
        data: { event },
      });
      if (isBranchUrl(event.url)) return;
      listener(event.url);
    });

    // Use this listener to handle Branch deep links only
    const unsubscribeBranch = branch.subscribe(({ error, params, uri }) => {
      if (error) {
        console.error('Error from Branch: ' + error);
        Sentry.captureException(error);
        return;
      }

      // If no error, params and uri will always be defined
      if (!params || !uri) return;
      Sentry.addBreadcrumb({
        message: 'branch.subscribe event',
        data: { params, uri },
      });

      // Don't handle regular deep links
      if (params['+non_branch_link'] || !isBranchUrl(uri)) return;

      // Don't handle something the user didn't actually click
      if (!params['+clicked_branch_link']) return;

      if (params['$deeplink_path']) {
        listener(prependSchema(params['$deeplink_path'] as string));
      } else {
        Sentry.captureMessage('Branch deep link missing $deeplink_path');
      }
    });

    return () => {
      unsubscribeBranch();
      linkingSub.remove();
    };
  },
};
android react-native branch.io
1个回答
0
投票

分支 SDK 不受 RN Expo 直接支持。 请参阅下面的线程, 链接:https://stackoverflow.com/a/78508991/25100904

© www.soinside.com 2019 - 2024. All rights reserved.