如何使用 .fetch 函数使 API 调用 IPV6 在 react-native 中兼容?

How to make API calls IPV6 compatible in react-native using the .fetch function?

我开发了一个用 React Native 编写的应用程序(适用于 IOS),它在 IPV4 网络中运行良好。但是,最近 Apple 发来消息说我的应用程序在 IPV6 网络中测试时无法运行。他们告诉我,我也必须让它与纯 IPV6 网络兼容。

问题是,如何使我现有的 API 调用与 IPV6 网络兼容?

我的API使用的是https协议,是通过域名调用的,不是原始IP。

我使用的示例提取调用是:

fetch(query,{
      method: 'post',
      headers: Utils.fetchHeaders('post')
      })
      .then(Utils.checkStatus)
      .then(Utils.parseJSON)
      .then(json => this._handleResponse(json))
      .catch(error => {

         this.setState({
          votingError: 'Sorry, there was an error!',
          loading: false
       });

      });

并且 API 端点采用以下格式:

https://www.myapidomain.com

感谢任何帮助。

fetch API 内部使用已经支持 IPv6 的 NSURLSession:

Most apps will not require any changes because IPv6 is already supported by NSURLSession and CFNetwork APIs.

来源:https://developer.apple.com/news/?id=05042016a

由于您没有使用 IPv4 地址进行提取 API 您应该可以开始了。

所以我怀疑还有其他东西(也许是某些第 3 方代码?)不与此合作。 Apple 是否向您提供了有关无法正常工作的更多详细信息?

我建议你按照this tutorial在你这边测试一下,找出不正确的地方。