问题描述
我开发了一个用 react native 编写的应用程序(用于 IOS),该应用程序在 IPV4 网络中运行良好.但是,最近 Apple 发送了一条消息,说我的应用程序在 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.
我使用的示例 fetch 调用是:
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
由于您没有在 fetch API 中使用 IPv4 地址,因此您应该可以继续使用.
Since you're not using IPv4 addresses with the fetch API you should be good to go.
所以我怀疑还有其他东西(可能是一些第 3 方代码?)不与此合作.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 函数在 react-native 中使 API 调用 IPV6 兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!