[RN] [IOS]是否可以将反应原生RCTLink与RNFirebase动态链接结合使用?

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

我目前正在通过RCTLinking API处理ios通用链接。出于某些原因,我需要使用Firebase动态链接,我想知道是否可以在我的应用程序中使用它们。我的问题是在以下方面的实施:

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

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

这似乎是不兼容的,因为我需要返回RCTLinkingManager和RNFirebaseLinks

有解决方案吗

ios firebase react-native react-navigation react-native-firebase
2个回答
0
投票

您可以在restorationHandler函数中使用下面的代码:

BOOL handled = [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
if (!handled) {
    handled = [RCTLinkingManager application:application
                   continueUserActivity:userActivity
                           restorationHandler:restorationHandler];

}
return handled;

0
投票

回答这个问题有点迟了,但目前提出的答案是行不通的。它将无法打开Firebase In-App Messaging中的操作,因为NO返回的RNFirebaseLinks将被RCTLinkingManager覆盖,YES将用于恢复处理程序。

如果您遇到此问题,请尝试以下操作:

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
        options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
   BOOL handledLink = [[RNFirebaseLinks instance] application:application openURL:url options:options];

  if (!handledLink) {
      handledLink = [RCTLinkingManager application:application openURL:url options:options];
  }
  return handledLink;
}

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

  BOOL handleRestore = [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler];

  if (handleRestore) {
    handleRestore = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
  }
  return handleRestore;
}

我目前的设置和需要是react-navigation v3和react-native-firebase v5

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