首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React本机深度链接在iOS上不起作用

React本机深度链接在iOS上不起作用
EN

Stack Overflow用户
提问于 2019-07-19 19:37:14
回答 1查看 2.1K关注 0票数 3

我已经将com.testApp://challenge/:id设置为深度链接网址。如果应用程序关闭了,并且我尝试从浏览器中以URL的形式访问它,它就可以正常工作。而且,这种情况只发生在iOS上。

但是如果App是打开的,并且我试图从浏览器访问上面的URL,它就会失败。

我已经使用了this article作为参考。虽然它有if (Platform.OS === 'android')的情况,但它没有帮助。

以下是我的代码:

代码语言:javascript
复制
  componentDidMount() {
    Linking.addEventListener('url', this.handleOpenURL);
    Linking.getInitialURL().then(url => {
      this.navigate(url);
    });
  }

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

  handleOpenURL = (event) => {
    if(event){
      this.navigate(event.url);
    }
  }

  navigate = (url) => { // E
    if (url){
      const route = url.replace(/.*?:\/\//g, '');
      const id = route.match(/\/([^\/]+)\/?$/)[1];
      const routeName = route.split('/')[0];

      if (routeName === 'challenge') {
        ChallengeService.find(id).then((challenge) => {
          Actions.challenge({ challenge: challenge });
        });
      };
    }
  }

以下是我的AppDelegate.m代码

代码语言:javascript
复制
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}

让我知道我做错了什么。

EN

Stack Overflow用户

发布于 2019-10-24 23:25:55

我也有同样的问题,我用这个解决了它。

代码语言:javascript
复制
<WebView
    source={{ uri }}
    onShouldStartLoadWithRequest={request => {
    console.log('request :', request);
    return request.url.startsWith(request.url);
    }}
/>
票数 -1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57111741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档