Ios 例外情况:;指定的URL具有不受支持的方案。仅支持http和https URL";
仅在ios中,我在从以下状态连接URL时遇到了这个问题:Ios 例外情况:;指定的URL具有不受支持的方案。仅支持http和https URL";,ios,react-native,Ios,React Native,仅在ios中,我在从以下状态连接URL时遇到了这个问题: componentDidMount(){ let unionUrl = this.props.datos.brand + " " + this.props.datos.name this.setState({ busqueda: unionUrl }) } Expo.WebBrowser.openBrowserAsync("https://www.example.com/sear
componentDidMount(){
let unionUrl = this.props.datos.brand + " " + this.props.datos.name
this.setState({
busqueda: unionUrl
})
}
Expo.WebBrowser.openBrowserAsync("https://www.example.com/search?query=" + this.state.busqueda)
const url = "http://example.com/search?query=" +`${this.props.datos.brand} ${this.props.datos.name}`
const urlOk = url.split(' ').join('+').toString()
await WebBrowser.openBrowserAsync(urlOk)
抛出的错误如下
,,
它似乎在注入数组,而不是字符串(?)
我以前在react中尝试过这种方法,效果很好我通过如下方式围绕道具解决了这个问题:
componentDidMount(){
let unionUrl = this.props.datos.brand + " " + this.props.datos.name
this.setState({
busqueda: unionUrl
})
}
Expo.WebBrowser.openBrowserAsync("https://www.example.com/search?query=" + this.state.busqueda)
const url = "http://example.com/search?query=" +`${this.props.datos.brand} ${this.props.datos.name}`
const urlOk = url.split(' ').join('+').toString()
await WebBrowser.openBrowserAsync(urlOk)
这个解决方案似乎在android和ios上都能工作,但有点让人扫兴,因为我的语言键盘布局中不存在“`”字符。对于以后的参考,这对我来说很有用
let query = textToSearch.replace(" ", "+");
let url = "https://www.google.com/search?q=" + query;
await WebBrowser.openBrowserAsync(url);
当您在谷歌搜索中输入短语时,每个空格都会转换为加号(+)。点击enter键并在浏览器中查看生成的URL后,您可以看到这一点。与上面的答案类似,但有一点上下文,如果要连接单词,请使用加号而不是空格