且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

应用程序将如何了解 iPhone 中互联网连接的可用性?

更新时间:2023-01-01 18:32:20

试试这个示例代码 示例
https://github.com/tonymillion/Reachability

Try with this sample code Sample and
https://github.com/tonymillion/Reachability

它还可以让您检查是否启用了 WiFi:

It will also allow you to check if WiFi is enabled:

Reachability* reachability = [Reachability sharedReachability];
[reachability setHostName:@"www.google.com"];    // set your host name here
NetworkStatus remoteHostStatus = [reachability remoteHostStatus];

if(remoteHostStatus == NotReachable) { }
else if (remoteHostStatus == ReachableViaWiFiNetwork) { }
else if (remoteHostStatus == ReachableViaCarrierDataNetwork) { }