Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.