Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Apps Using WLAN & Cellular Setting

How to get Apps Using WLAN & Cellular Setting setting status in the picture below ?
How can I check that status(None, WLAN, WLAN&Cellular) for my App, so that I can show an alert to remind user of open this switch ~

like image 803
Shawn Wang Avatar asked Oct 27 '25 03:10

Shawn Wang


1 Answers

When Reachability is NotReachable, there are 2 situation ,

  1. The wifi is not connected
  2. The Apps Using WLAN & Cellular Setting is off

If we can get the SSID of current wifi, we can judge that the wifi is connected and the network switch is off ~

#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);
    }
like image 151
Shawn Wang Avatar answered Oct 29 '25 19:10

Shawn Wang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!