使用WLAN获取应用程序&蜂窝设置

时间:2016-09-26 10:08:22

标签: ios iphone setting

如何在下图中获得Apps Using WLAN & Cellular Setting设置状态?
如何查看我的应用程序的状态(无,WLAN,WLAN和移动电话),以便我可以显示警告以提醒用户打开此开关〜

1 个答案:

答案 0 :(得分:1)

我终于找到了解决方案〜

:d

ReachabilityNotReachable时,有两种情况,

  1. 未连接wifi
  2. Apps Using WLAN & Cellular Setting     关闭
  3. 如果我们可以获得当前wifi的SSID,我们可以判断wifi已连接且网络开关已关闭〜

    #import <SystemConfiguration/CaptiveNetwork.h>
    
        BOOL networkSwitchOff = NO;
        Reachability *reach = [Reachability reachabilityForInternetConnection];
        NetworkStatus status = [reach currentReachabilityStatus];
        if(status==NotReachable){  //Reachability NotReachable
            NSArray *supportedInterfaces = (__bridge_transfer id)CNCopySupportedInterfaces();
            id info = nil;
            NSString *ssid = nil;
            for (NSString *networkInfo in supportedInterfaces) {
                info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)networkInfo);
                if (info && [info count])
                    break;
            }
    
            if (info) {
                NSDictionary *dctySSID = (NSDictionary *)info;
                //we can't get ssid if wifi is not connected
                ssid = [dctySSID objectForKey:@"SSID"]; 
            }
            networkSwitchOff = (ssid!=nil);
        }