Skip to content

Instantly share code, notes, and snippets.

@doluvor
Created October 17, 2016 05:53
Show Gist options
  • Save doluvor/03b47f1fb378657347507f32d79af1d4 to your computer and use it in GitHub Desktop.
Save doluvor/03b47f1fb378657347507f32d79af1d4 to your computer and use it in GitHub Desktop.
Observe iOS network change
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
onNotifyCallback, // callback
CFSTR("com.apple.system.config.network_change"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
static void onNotifyCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
NSString* notifyName = (NSString*)name;
// this check should really only be necessary if you reuse this one callback method
// for multiple Darwin notification events
if ([notifyName isEqualToString:@"com.apple.system.config.network_change"]) {
// use the Captive Network API to get more information at this point
// http://stackoverflow.com/a/4714842/119114
} else {
NSLog(@"intercepted %@", notifyName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment