iOS可达性类如何工作,为什么IP地址为169.254.0.0? [英] How does the iOS Reachability class work, and why the IP Address 169.254.0.0?
问题描述
iOS Reachability类如何工作,IP地址169.254.0.0有何特别之处?
How does the iOS Reachability class work, and what's so special about the IP Address 169.254.0.0?
我试图确定Wi-Fi是否已打开,而与它是否连接到实际的Wi-Fi网络无关.
I'm trying to figure out whether Wi-Fi is on, independent of whether it is connected to an actual Wi-Fi network or not.
关于SO的这个问题,我还没有找到满意的答案,甚至试图回答这个问题的答案对我也不起作用.
I haven't found a satisfactory answer for this question on SO, and even the answers that try to answer this don't work for me.
推荐答案
当您无法从DHCP获取IP地址时,它将自动为您分配169.254.x.x范围内的随机地址.因此,如果您具有这样的IP地址,则意味着您已连接到网络,并设置为使用DHCP获取地址,但无法从DHCP获取IP地址.
When you fail to get an IP address from DHCP, it will automatically assign you a random address in the 169.254.x.x range. So if you have an IP address like this, it means you're connected to a network, and set to use DHCP to get an address, but it is unable to obtain an IP address from DHCP.
似乎没有任何方法可以简单地检测是否启用了wifi且未连接到网络,因此我认为您不走运.最好的办法就是检测您是否已连接到wifi网络,但是即使您不在外面,也经常无法连接到wifi网络,即使已启用该无线网络.
There doesn't appear to be any way to simply detect if wifi is enabled and not connected to a network, so I think you're out of luck there. The best you can do is detect if you're connected to a wifi network, but often if you're out and about, you won't be connected to a wifi network even though it is enabled.
这篇关于iOS可达性类如何工作,为什么IP地址为169.254.0.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!