-
-
Save perfaram/ca3521ea832c69673bea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Eric Wolfe: Added support for checking if mobile radios are enabled on the device | |
// Original source: http://www.enigmaticape.com/blog/determine-wifi-enabled-ios-one-weird-trick | |
#import <Foundation/Foundation.h> | |
#import <ifaddrs.h> | |
#import <net/if.h> | |
#import <SystemConfiguration/CaptiveNetwork.h> | |
@interface ERWNetworkStatus : NSObject | |
+ (BOOL) isMobileDataEnabled; | |
+ (BOOL) isWiFiEnabled; | |
+ (BOOL) isWiFiConnected; | |
+ (NSString *) BSSID; | |
+ (NSString *) SSID; | |
@end | |
@implementation ERWNetworkStatus | |
+ (BOOL) isMobileDataEnabled { | |
NSCountedSet * cset = [NSCountedSet new]; | |
struct ifaddrs *interfaces; | |
if( ! getifaddrs(&interfaces) ) { | |
for( struct ifaddrs *interface = interfaces; interface; interface = interface->ifa_next) { | |
if ( (interface->ifa_flags & IFF_UP) == IFF_UP ) { | |
[cset addObject:[NSString stringWithUTF8String:interface->ifa_name]]; | |
} | |
} | |
} | |
return [cset countForObject:@"pdp_ip0"] > 0 ? YES : NO; | |
} | |
+ (BOOL) isWiFiEnabled { | |
NSCountedSet * cset = [NSCountedSet new]; | |
struct ifaddrs *interfaces; | |
if( ! getifaddrs(&interfaces) ) { | |
for( struct ifaddrs *interface = interfaces; interface; interface = interface->ifa_next) { | |
if ( (interface->ifa_flags & IFF_UP) == IFF_UP ) { | |
[cset addObject:[NSString stringWithUTF8String:interface->ifa_name]]; | |
} | |
} | |
} | |
return [cset countForObject:@"awdl0"] > 1 ? YES : NO; | |
} | |
+ (NSDictionary *) wifiDetails { | |
return | |
(__bridge NSDictionary *) | |
CNCopyCurrentNetworkInfo( | |
CFArrayGetValueAtIndex( CNCopySupportedInterfaces(), 0) | |
); | |
} | |
+ (BOOL) isWiFiConnected { | |
return [self wifiDetails] == nil ? NO : YES; | |
} | |
+ (NSString *) BSSID { | |
return [self wifiDetails][@"BSSID"]; | |
} | |
+ (NSString *) SSID { | |
return [self wifiDetails][@"SSID"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment