将 React Native 升级到 0.0.72 后通用链接不起作用

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

当我们使用之前的 React Native 版本时,我们有适用于 React Native 应用程序的通用链接

0.0.67
。我们现在正在升级到 React Native 版本
0.0.72
,通用链接不再有效。我按照 RN 的官方升级文档进行操作,其中
AppDelegate.m
文件现在更改为
AppDelegate.mm
。我按照React Native中的指南设置Linking,并添加了它所声明的两个内容,即xcode中标头搜索路径中的LinkingIOS文件夹,以及新的
AppDelegate.mm
中的openUrl和 continueUserActivity 的两个函数。我还验证了配置文件、Web 服务器上的 AASA 文件以及列出关联域的权利是否仍然正确设置。配置文件看起来是正确的,因为当我在仍使用 React Native 67 的旧分支上进行测试时,通用链接工作正常。

当我点击 IOS 模拟器上的通用链接时,xcode 构建日志或终端中运行的 Metro 上没有出现错误,它只是在浏览器中打开,而根本不打开应用程序,无论应用程序是否在背景或完全被杀。

问题似乎缩小到 AppDelegate 函数未被调用,我通过在那些未在日志中打印的函数中添加

RCTLog()
语句来验证这一点。

#import <Firebase.h>
#import "AppDelegate.h"
#import <React/RCTLinkingManager.h>
#import <React/RCTBundleURLProvider.h>

@implementation RNAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  
  // Following if statement is fix for https://quickbase.atlassian.net/browse/MB1-462
  // Code is taken from this thread: https://github.com/mCodex/react-native-sensitive-info/issues/303
  if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HAS_RUN_BEFORE"] == NO) { 
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HAS_RUN_BEFORE"]; 
    NSArray *secItemClasses = [NSArray arrayWithObjects: (__bridge id)kSecClassGenericPassword, (__bridge id)kSecClassInternetPassword, (__bridge id)kSecClassCertificate, (__bridge id)kSecClassKey, (__bridge id)kSecClassIdentity, nil]; 
    for (id secItemClass in secItemClasses) { 
      NSDictionary *spec = @{(__bridge id)kSecClass: secItemClass}; SecItemDelete((__bridge CFDictionaryRef)spec); 
    } 
  }
  
  self.moduleName = @"myAppName";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
// iOS 9.x or newer
- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
 restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
 return [RCTLinkingManager application:application
                  continueUserActivity:userActivity
                    restorationHandler:restorationHandler];
}
@end

我还可能错过什么?或者还有什么其他方法可以调试问题?

react-native appdelegate ios-universal-links universal-link
1个回答
0
投票

找出我的问题的根本原因。我的 ios/podfile 和 project.pbxproj 中的代码签名被禁用。这并没有使权利在应用程序构建中可用。由于权利具有关联域功能,因此通用链接失败。

我必须删除下面文件中的这些行,才能在构建中选择权利。

来自 podfile:

config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"

从project.pbxproj中删除了存在于两个位置的这些行,一处用于调试,一处用于发布构建:

CODE_SIGNING_ALLOWED = NO;
CODE_SIGNING_REQUIRED = NO;

清理并构建应用程序后,通用链接开始工作

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