Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sergenes/9524457 to your computer and use it in GitHub Desktop.
Save sergenes/9524457 to your computer and use it in GitHub Desktop.
#pragma mark - NetworkHelper.h
- (void)getHotspotNameWithCompletion:(void (^)(void))completionBlock andFail:(void (^)(void))failBlock;
#pragma mark - NetworkHelper.m
- (void)getHotspotNameWithCompletion:(void (^)(void))completionBlock andFail:(void (^)(void))failBlock
{
dispatch_async(queue, ^{
localIPAddress = [self localWiFiIPAddress];
#if TARGET_IPHONE_SIMULATOR
hotSpotName = @"SIMULATOR";
#else // TARGET_IPHONE_SIMULATOR
CFArrayRef interfaces = CNCopySupportedInterfaces();
CFIndex count = CFArrayGetCount(interfaces);
for (int i = 0; i < count; i++) {
CFStringRef interface = CFArrayGetValueAtIndex(interfaces, i);
CFDictionaryRef netinfo = CNCopyCurrentNetworkInfo(interface);
if (netinfo && CFDictionaryContainsKey(netinfo, kCNNetworkInfoKeySSID)) {
hotSpotName = (__bridge NSString *)CFDictionaryGetValue(netinfo, kCNNetworkInfoKeySSID);
}
if (netinfo)
CFRelease(netinfo);
}
CFRelease(interfaces);
//Delay for TEST
BOOL stop = NO;
while (!stop) {
[NSThread sleepForTimeInterval:1];
stop = YES;
}
//
#endif
dispatch_async(dispatch_get_main_queue(), ^{
if(hotSpotName && localIPAddress){
completionBlock();
}else{
failBlock();
}
});
});
}
#pragma mark - Call
[[NetworkHelper shared] getHotspotNameWithCompletion:^{
[self.hotSpotNameLabel setText:[[NetworkHelper shared] hotSpotName]];
[self.localIPLabel setText:[[NetworkHelper shared] localIPAddress]];
} andFail:^{
[self.hotSpotNameLabel setText:@"Check Wi-Fi"];
[self.localIPLabel setText:@"..."];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment