如何知道网络状态是否是iOS上的WiFi热点

时间:2017-11-28 08:36:53

标签: ios afnetworking reachability

现在我可以识别WiFi / 2G / 3G / 4G,但当状态是WiFi热点时,AFNetworkReachabilityManagerReachability也会将状态识别为WiFi。非常感谢请帮我实现这一要求。

1 个答案:

答案 0 :(得分:-2)

我找到了正确的方法:

- (void)startMonitorWifiChange {
    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
                                    NULL,
                                    &onNotifyCallback,
                                    CFSTR("com.apple.system.config.network_change"),
                                    NULL,
                                    CFNotificationSuspensionBehaviorDeliverImmediately);
}
static void onNotifyCallback(CFNotificationCenterRef center,
                             void *observer,
                             CFStringRef name,
                             const void *object,
                             CFDictionaryRef userInfo) {
    if (CFStringCompare(name, CFSTR("com.apple.system.config.network_change"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
        //TODO when wifi changed
        [[BaiduLocationManager sharedManager].baiduLocationManager requestNetworkState];
    }
    else {
        NBLog(@"intercepted %@", name);
    }
}
- (void)stopMonitorWifiChange {
    CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(),
                                       NULL,
                                       CFSTR("com.apple.system.config.network_change"),
                                       NULL);
}
相关问题