可达性和IPv6 [英] Reachability and IPv6

查看:117
本文介绍了可达性和IPv6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个项目使用Apple的Reachability类来监控网络状态,并在发生变化时收到通知。

One of my project uses the Apple's Reachability class in order to be monitor the network state and be notified in case of changes.

阅读这篇文章关于支持IPv6我想知道是否要在这个类中使用它以使其与IPv6一起工作。

After reading this article about supporting IPv6 I was wondering if were to be made to this class to make it work with IPv6.

我在同一篇文章,一切似乎都运行正常,但可能是设置有问题。

I set up an IPv6 network following the same article and everything seems to work fine but maybe there is an issue with the setup.

Reachability类的部分是检查Internet连接是否与现在一样使用IPv6,还是需要进行一些更改?

推荐答案

Apple自己的简短回答( https://developer.apple.com/videos/play/wwdc2015/719/ ~10:30 - 尽管我建议全程观看视频 - 或者至少看看关键字点这里: http://www.internetsociety.org/deploy360/blog/2015/06/video -of-apple-wwdc-session-about-ipv6-and-ios-9-now-available-and-some-screenshots / ):

Short answer from Apple itself (https://developer.apple.com/videos/play/wwdc2015/719/ at ~10:30 - though I would recommend to watch the video in full - or at least look through at the key points here: http://www.internetsociety.org/deploy360/blog/2015/06/video-of-apple-wwdc-session-about-ipv6-and-ios-9-now-available-and-some-screenshots/):

只需尝试连接。

来自 https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/UnderstandingandPreparingfortheIPv6Transition /UnderstandingandPreparingfortheIPv6Transition.html#//apple_ref/doc/uid/TP40010220-CH213-SW25 重申了这一点:


不使用预检连接

可达性API(参见SCNetworkReachabi) lity参考)是
,用于在识别连接
问题后用于诊断目的。许多应用程序错误地使用这些API通过调用
SCNetworkReachabilityCreateWithAddress方法并向其传递IPv4
地址0.0.0.0来主动检查
Internet连接,这表明路由器上有
网络。但是,路由器的存在并不能保证存在
的Internet连接。通常,避免预检网络
可达性。只是尝试建立连接并优雅地处理
失败。如果必须检查网络可用性,请避免使用SCNetworkReachabilityCreateWithAddress方法调用
。调用
SCNetworkReachabilityCreateWithName方法并将其传递给主机名

The Reachability APIs (see SCNetworkReachability Reference) are intended for diagnostic purposes after identifying a connectivity issue. Many apps incorrectly use these APIs to proactively check for an Internet connection by calling the SCNetworkReachabilityCreateWithAddress method and passing it an IPv4 address of 0.0.0.0, which indicates that there is a router on the network. However, the presence of a router doesn’t guarantee that an Internet connection exists. In general, avoid preflighting network reachability. Just try to make a connection and gracefully handle failures. If you must check for network availability, avoid calling the SCNetworkReachabilityCreateWithAddress method. Call the SCNetworkReachabilityCreateWithName method and pass it a hostname instead.

某些应用程序还传递SCNetworkReachabilityCreateWithAddress方法
IPv4地址169.254 .0.0,一个自我分配的链路本地地址,以
检查有效的Wi-Fi连接。要检查Wi-Fi或蜂窝
连接,请查找网络可达性标志
kSCNetworkReachabilityFlagsIsWWAN。

Some apps also pass the SCNetworkReachabilityCreateWithAddress method an IPv4 address of 169.254.0.0, a self-assigned link-local address, to check for an active Wi-Fi connection. To check for Wi-Fi or cellular connectivity, look for the network reachability flag kSCNetworkReachabilityFlagsIsWWAN instead.

这篇关于可达性和IPv6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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