iOS 检测网络切换

  CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center

                                    NULL, // observer

                                    onNotifyCallback, // callback

                                    CFSTR("com.apple.system.config.network_change"), // event name

                                    NULL, // object

                                    CFNotificationSuspensionBehaviorDeliverImmediately);

 

staticvoid onNotifyCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, constvoid *object, CFDictionaryRef userInfo)

{

    NSString* notifyName = (__bridgeNSString*)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"]) {

}

}

posted on 2015-04-27 10:38  XCoderLiu  阅读(818)  评论(0编辑  收藏  举报

导航