Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
@alirp88

This comment has been minimized.

Show comment
Hide comment
@alirp88

alirp88 Aug 24, 2016

I created a pod base on this gist
SMTWiFiStatus

alirp88 commented Aug 24, 2016

I created a pod base on this gist
SMTWiFiStatus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment