ios - 异常 : "The specified URL has an unsupported scheme. Only http and https URLs are supported"

标签 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/search?query=" + this.state.busqueda)

抛出的错误是这样的

the error thrown is this ,
似乎它正在注入(inject)一个数组,而不是一个字符串(?)

我之前在 react 中尝试过这种方法并且效果很好

最佳答案

我通过包围这样的 Prop 来解决它:

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,但有点令人失望,因为我的语言的键盘布局中不存在“`”字符。

关于ios - 异常 : "The specified URL has an unsupported scheme. Only http and https URLs are supported",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51960709/

相关文章:

ios - 如何隐藏/显示导航栏中的右键

c# - 检测用户跳到 AVPlayer 视频的结尾

iOS,如何禁用有关已弃用方法的某些警告

react-native - 如何在 react-native 中获取在 webview 中设置的 cookie?

ios - 将 cocoapods 添加到成熟的 react native 项目后,我的应用程序存档为单独的应用程序,而不是对现有应用程序的更新

objective-c - UIScrollView - 是否可以知道是手动滚动还是以编程方式滚动?

javascript - window.print()和window.close()函数Safari IOS在不等待打印预览的情况下关闭窗口

react-native - 如何使用 React 原生选择框

javascript - Android React Native 应用程序在 getUserMedia WebRTC 调用时崩溃

react-native - 如何在 React Native 中获取电话号码?