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.
Step to run the application: Open the terminal and type the following command. Output: Now open localhost:300 and in the console, the data is fetched. 3. Async-Await: This is the preferred way of fetching the data from an API.
It's just that simple! Start your app as usual but don't forget to give an IP address and a port, this will help you solve the Network Request Failed error. And on your mobile app, make sure to use the correct URL in your request. Make sure that CORS is enabled on your backend to avoid errors related to CORS.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With