如何使用.fetch函数使API调用IPV6在react-native中兼容? [英] How to make API calls IPV6 compatible in react-native using the .fetch function?

查看:254
本文介绍了如何使用.fetch函数使API调用IPV6在react-native中兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个用react native编写的应用程序(用于IOS),该应用程序在IPV4网络中运行良好.但是,最近苹果公司发送了一条消息,说我的应用程序在IPV6网络中进行测试时无法正常工作.他们告诉我,我也必须使其与仅IPV6的网络兼容.

I have developed an app (for IOS) written in react native which is working good in IPV4 networks. However, recently Apple has sent a message saying that my app did not work when tested in an IPV6 network. They told me that I had to make it compatible with IPV6-only networks too.

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

The question is, how can I make my existing API calls compatible with an IPV6 network?

我的API使用https协议,并且通过域名而不是原始IP进行调用.

My API uses the https protocol and it is called by domain name, not a raw IP.

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

A sample fetch call that I use is:

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端点的格式如下:

and the API endpoint is in following format:

https://www.myapidomain.com

任何帮助表示赞赏.

推荐答案

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

The fetch API internally uses NSURLSession which already supports IPv6:

大多数应用将不需要任何更改,因为NSURLSession和CFNetwork API已经支持IPv6.

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

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

由于您未在获取API中使用IPv4地址,因此应该可以使用.

Since you're not using IPv4 addresses with the fetch API you should be good to go.

因此,我怀疑还有其他问题(也许一些第三方代码?)与此不合作. Apple是否向您提供了有关无法正常工作的更多详细信息?

So I suspect there's something else (maybe some 3rd party code?) not cooperating with this. Did Apple provide you with more details about what was not working?

我建议您遵循本教程在您这边进行测试,找出不正确的地方.

I suggest you follow this tutorial to test it on your side and find out what's incorrect.

这篇关于如何使用.fetch函数使API调用IPV6在react-native中兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆