我已经将com.testApp://challenge/:id设置为深度链接网址。如果应用程序关闭了,并且我尝试从浏览器中以URL的形式访问它,它就可以正常工作。而且,这种情况只发生在iOS上。
但是如果App是打开的,并且我试图从浏览器访问上面的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];
}让我知道我做错了什么。
发布于 2019-10-24 23:25:55
我也有同样的问题,我用这个解决了它。
<WebView
source={{ uri }}
onShouldStartLoadWithRequest={request => {
console.log('request :', request);
return request.url.startsWith(request.url);
}}
/>https://stackoverflow.com/questions/57111741
复制相似问题