0

We had universal links working for our react native app when we were on the previous React native version 0.0.67. We are now upgrading to React Native version 0.0.72 and universal links are no longer working. I followed the official upgrade document for RN, per which the AppDelegate.m file now changed to AppDelegate.mm. I followed the guide to setup Linking in React Native, and added both things it states, the LinkingIOS folder in the header search paths in xcode, as well as the two functions for openUrl and continueUserActivity in the new AppDelegate.mm. I have also verified that the configuration files are still setup correctly, the AASA file on the web server and the entitlements that lists the associated domains. The configuration files seem correct because when i test on the older branch where we are still on React Native 67, Universal links are working fine.

There are no errors appearing on xcode build logs or on metro running in the terminal when I click on a universal link on an IOS simulator, it simply opens in browser without opening the app at all, no matter if the app is running in the background or totally killed.

The issue seems to be narrowed down to AppDelegate functions not getting called, which I verified by adding a RCTLog() statement in those functions that does not get printed in the logs.

#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

What else could I be missing? Or what are other ways to debug the problem?

1

1 Answer 1

0

Find out the root cause for my issue. The code signing in my ios/podfile and project.pbxproj was disabled. That was not making the entitlements available in app builds. And since the entitlements has the associated-domains capabilities, universal links were failing.

I had to remove these lines in the files below for entitlements to get picked in the build.

From podfile:

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

From project.pbxproj, removed these lines that were present at two places, one for debug and one for release build:

CODE_SIGNING_ALLOWED = NO;
CODE_SIGNING_REQUIRED = NO;

After that just cleaned and build the app, universal links started working

Not the answer you're looking for? Browse other questions tagged or ask your own question.