Created
May 21, 2014 21:22
-
-
Save enigmaticape/4e8d467571680a3bf774 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
#import <Foundation/Foundation.h> | |
#import <ifaddrs.h> | |
#import <net/if.h> | |
#import <SystemConfiguration/CaptiveNetwork.h> | |
@interface SMTWiFiStatus : NSObject | |
- (BOOL) isWiFiEnabled; | |
- (BOOL) isWiFiConnected; | |
- (NSString *) BSSID; | |
- (NSString *) SSID; | |
@end | |
@implementation SMTWiFiStatus | |
- (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
I created a pod base on this gist
SMTWiFiStatus