我正在构建使用自定义方案(深层链接)的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(来自应用程序委托)。
正如解释here,我试图查看是否在didFinishLaunchingWithOptions中的launchOptions中发送了任何内容。但这显然只是在首次启动时才调用。
我已经读过official doc,但是找不到解决我问题的方法。
答案在doc中
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
。
下一次,我将更仔细地阅读文档。