Created
October 17, 2016 05:53
-
-
Save doluvor/03b47f1fb378657347507f32d79af1d4 to your computer and use it in GitHub Desktop.
Observe iOS network change
This file contains 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
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