3

我目前正在通过 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

有什么解决办法吗?

4

3 回答 3

2

回答这个问题有点晚了,但目前提出的答案是行不通的。它将无法从 Firebase 应用内消息中打开操作,因为返回NO的操作将被恢复处理程序的withRNFirebaseLinks覆盖。RCTLinkingManagerYES

如果您遇到这种情况,请尝试以下操作:

- (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-navigationv3 和react-native-firebasev5

于 2019-04-05T00:11:38.043 回答
0

我的解决方案是:

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
        options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  if (url == nil) return false;
  BOOL handled = [[RNFirebaseLinks instance]
                  application:application
                  openURL:url
                  options:options
                  ] || [RCTLinkingManager
                        application:application
                        openURL:url
                        options:options
                        ];
  return handled;
}

- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray *))restorationHandler {
  BOOL handled = [[RNFirebaseLinks instance]
                   application:application
                   continueUserActivity:userActivity
                   restorationHandler:restorationHandler
                   ] || [RCTLinkingManager
                         application:application
                         continueUserActivity:userActivity
                         restorationHandler:restorationHandler
                         ];
   return handled;
}

react-native-firebase: 5.5.6, react-navigation 3.X 不将 url 控制为 nil 会导致启动应用程序时崩溃。

于 2019-11-15T16:41:14.337 回答
0

您可以在restorationHandler函数中包含类似以下代码的内容:

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

}
return handled;
于 2018-07-16T14:06:34.237 回答