现在我只能识别WiFi/2G/3G/4G,但当状态为WiFi hotspot时,AFNetworkReachabilityManager或Reachability也会将状态识别为WiFi。请帮助我达到这个要求,非常感谢。
发布于 2017-12-05 14:39:52
我找到了正确的方法:
- (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);
}https://stackoverflow.com/questions/47527173
复制相似问题