0

问题和背景

我正在构建一个使用自定义方案(深度链接)的 Maccatalyst 应用程序。

当我的应用程序正在运行并单击指向我的应用程序的链接时,我的应用程序将打开并接收打开的 url。

但是,当我的应用程序关闭时,我点击了我的应用程序的链接,它会打开但没有收到打开的 url。ios上不会出现这个问题。

(仅供参考,该应用程序是用 react-native 0.59 编写的,但问题不在于 javascript 方面)。

谁可以帮我这个事 ?

代码

她是我的 AppDelegate.m 文件

#import <CoreGraphics/CGGeometry.h>
#import "AppDelegate.h"

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

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                             moduleName:@"myapp"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

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

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  // Listen to incoming app links during app execution
  return [RCTLinkingManager application:application openURL:url options:options];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
 restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
  // Listen to universal links in iOS and tvOS
  // does not work when app is closed in debug mode
  return [RCTLinkingManager application:application
                   continueUserActivity:userActivity
                     restorationHandler:restorationHandler];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    ...
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    ...
}

@end

我试过的

  • 我检查了问题不在 javascript 端,因为当应用程序关闭时,既不会调用 application:openURL:options 也不会调用 application:continueUserActivity:restorationHandler (来自应用程序委托)。

  • 正如这里所解释的,我试图查看是否在 didFinishLaunchingWithOptions 的 launchOptions 中发送了任何内容。但这显然只在第一次发布时才被调用。

  • 我已阅读官方文档,但找不到解决问题的方法。

4

1 回答 1

0

答案在文档中

This method is not called if your implementations return NO from both the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods. (If only one of the two methods is implemented, its return value determines whether this method is called.) If your app implements the applicationDidFinishLaunching: method instead of application:didFinishLaunchingWithOptions:, this method is called to open the specified URL after the app has been initialized.

所以我需要注意UIApplicationLaunchOptionsURLKey选项中的关键didFinishLaunchingWithOptions

下一次,我会更仔细地阅读文档。

于 2020-06-10T08:16:15.690 回答