Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 句柄URL方案本地和Swift响应_Javascript_Ios_Swift_Xcode_React Native - Fatal编程技术网

Javascript 句柄URL方案本地和Swift响应

Javascript 句柄URL方案本地和Swift响应,javascript,ios,swift,xcode,react-native,Javascript,Ios,Swift,Xcode,React Native,我想在我的react本机应用程序中处理自定义URL方案。因此,我首先在根组件中的JS代码中添加了一个eventListener,如下所示: componentDidMount() { Linking.addEventListener('url', this.handleOpenURL); } componentWillUnmount() { Linking.removeEventListener('url', this.handleOpenURL); } handleOpen

我想在我的react本机应用程序中处理自定义URL方案。因此,我首先在根组件中的JS代码中添加了一个eventListener,如下所示:

componentDidMount() {
    Linking.addEventListener('url', this.handleOpenURL);
}

componentWillUnmount() {
    Linking.removeEventListener('url', this.handleOpenURL);
}

handleOpenURL = event => {
    console.log('event', event);
};
在我的Xcode应用程序中,我添加了一个自定义URL方案“com.myScheme”

当我试图在AppDelegate.swift中添加函数以处理深度链接时,出现了我的问题

以下是我的功能:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
    print(url)
    return true
}
似乎返回true不足以触发应用程序中的侦听器

我知道react原生文档中有一个Objective-C方法:

#import <React/RCTLinkingManager.h>

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}
#导入
-(BOOL)应用程序:(UIApplication*)应用程序
openURL:(NSURL*)url
选项:(NSDictionary*)选项
{
返回[RCTLinkingManager应用程序:应用程序openURL:url选项:选项];
}
但为了提高我的语言技能,我只想在我的项目中与Swift打交道。问题是我找不到任何使用Swift实现此功能的示例

这就是为什么我请求一些帮助来实现这个方法,然后在我的RN应用程序中触发我的事件


感谢您的理解:)

关于您的AppDelegate方法,swift版本应为:

public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    return RCTLinkingManager.application(app, open: url, options: options)
}

谢谢,这正是我要找的!它就像一个符咒;)如何通过导入在swiftJust中导入
RCTLinkingManager
React@Hurobaki你是说这件事?你能在这里分享你的swift文件代码吗?我的意思是你应该已经在你的顶部文件中导入了React包
import React
。别忘了在桥接头中导入。h`#import«React/RCTLinkingManager.h»。如何在swift中导入RCTLinkingManager?