小编chi*_*rry的帖子

为什么 Linking.getInitialURL 总是返回 null?

我成功地使用深层链接从共享扩展打开我的应用程序。如果应用程序已经在运行,那么我会在ComponentDidMount使用中获取信息Linking.addEventListener('url', this.handleOpenURL);

如果应用程序尚未运行,我希望能够Linking.getInitialURL();根据文档(https://facebook.github.io/react-native/docs/linking)使用。除了它总是出现null在我身上。该链接是我的应用程序的打开方式,但无论如何,都显示为空。我在 App.js 的 componentDidMount 中有该代码。

我在反应原生 59.2。

这是我的 AppDelegate.m

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"MYMODULENAME"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [UIColor blackColor];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- …
Run Code Online (Sandbox Code Playgroud)

ios react-native

8
推荐指数
2
解决办法
5012
查看次数

标签 统计

ios ×1

react-native ×1