How to make API calls IPV6 compatible in react-nat

2019-06-15 22:22发布

问题:

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.

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

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
       });

      });

and the API endpoint is in following format:

https://www.myapidomain.com

any help appreciated.

回答1:

The fetch API internally uses NSURLSession which already supports IPv6:

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

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

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

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.