简体   繁体   English

Firebase iOS/React Native 上的动态链接仅在应用程序运行时有效

[英]Firebase Dynamic Links on iOS/React Native only working when app is running

I am using Firebase's Dynamic Links (8.11.0) to open a React Native (0.66.4) app with a specific URL.我正在使用Firebase 的动态链接(8.11.0) 打开具有特定 URL 的 React Native (0.66.4) 应用程序。

In my AppDelegate.m file, I'm handling the URL this way:在我的AppDelegate.m文件中,我以这种方式处理 URL:

- (BOOL)application:(UIApplication *)application
continueUserActivity:(nonnull NSUserActivity *)userActivity
 restorationHandler:
#if defined(__IPHONE_12_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
#else
  (nonnull void (^)(NSArray *_Nullable))restorationHandler {
#endif  // __IPHONE_12_0
        FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:userActivity.webpageURL];
    
        if (dynamicLink) {
          if (dynamicLink.url) {
            NSLog(@"dynamicLink.url %@", dynamicLink.url);
            return [RCTLinkingManager application:application openURL:dynamicLink.url options:[NSMutableDictionary dictionary]];
          }
        }
    
        return [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
                                                 completion:^(FIRDynamicLink * _Nullable dynamicLink, NSError * _Nullable error) {
          if (error) {
            NSLog(@" dynamicLink.url ERROR %@", error);
          }
          if (dynamicLink) {
            if (dynamicLink.url) {
              NSLog(@" dynamicLink.url %@", dynamicLink.url);
              // ******** This line is executed as expected in both cases *******
              [RCTLinkingManager application:application openURL:dynamicLink.url options:[NSMutableDictionary dictionary]];
            } else {
              [RCTLinkingManager application:application openURL:userActivity.webpageURL options:[NSMutableDictionary dictionary]];
            }
          } else {
            [RCTLinkingManager application:application openURL:userActivity.webpageURL options:[NSMutableDictionary dictionary]];
          }
        }];
  }

My Info.plist file specifies my custom domain:我的Info.plist文件指定了我的自定义域:

<key>FirebaseDynamicLinksCustomDomains</key>
<array>
  <string>https://join.mysite.app</string>
</array>

And my Associated Domains specify我的关联域指定

applinks:join.mysite.app

With this in place, my React Native code, via Linking.getInitalURL() is receiving the link (specified here ) that I expect, but only if the app is already running when the short link is clicked .有了这个,我的 React Native 代码,通过Linking.getInitalURL()正在接收我期望的link在此处指定),但前提是当单击短链接时应用程序已经在运行

When my app is not running, the same code noted in the comments above is executed, with the same inputs and outputs that I expect, but the Linking.getInitalURL() call is giving me the short link, not the resolved link that is passed to RCTLinkingManager .当我的应用程序运行时,将执行上面注释中提到的相同代码,具有我期望的相同输入和输出,但Linking.getInitalURL()调用给我的是短链接,而不是传递的解析链接到RCTLinkingManager

I would expect that with the same code path/data, the behavior would be the same, but it's only correct when the app is already running.我希望使用相同的代码路径/数据,行为将是相同的,但只有当应用程序已经运行时它才是正确的。 Am I missing a step?我错过了一步吗?

From the sample, you shared you only implemented the continueUserActivity method that intercepts links when the application is already open.从示例中,您分享了您只实现了continueUserActivity方法,该方法在应用程序已经打开时拦截链接。

You also need to implement openURL method like their documentation states here您还需要实现openURL方法,如他们的文档状态here

In the end, I would highly advise using an already build library that works with react-native最后,我强烈建议使用与 react-native 一起使用的已构建

If you really insist on building this functionality on your own, at least you can check out their source code here如果你真的坚持自己构建这个功能,至少你可以在这里查看他们的源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM