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

问题描述 投票:1回答:1

我已将com.testApp://challenge/:id设置为深层链接URL。如果应用已关闭,并且我尝试通过浏览器作为URL来运行,则效果很好。另外,这仅适用于iOS。

但是如果打开了应用程序却失败了,我尝试从浏览器访问上述URL。

我已使用this article作为参考。尽管它具有if (Platform.OS === 'android')条件,但没有帮助。

以下是我的代码:

  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代码

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}

让我知道我做错了。

react-native deep-linking react-native-ios react-native-router-flux
1个回答
0
投票

我遇到了同样的问题,并且解决了这个问题

<WebView
    source={{ uri }}
    onShouldStartLoadWithRequest={request => {
    console.log('request :', request);
    return request.url.startsWith(request.url);
    }}
/>
© www.soinside.com 2019 - 2024. All rights reserved.