[英]How to know if the network state is WiFi hotspot on iOS
Now I can just recognize WiFi/2G/3G/4G, but when the state is WiFi hotspot, AFNetworkReachabilityManager
or Reachability
also recognize the state as WiFi. 现在,我可以识别WiFi / 2G / 3G / 4G,但是当状态为WiFi热点时, AFNetworkReachabilityManager
或Reachability
也可以将状态识别为WiFi。 Please help me to achieve this requirement, thanks a lot. 非常感谢,请帮助我达到这一要求。
I had found the right way: 我找到了正确的方法:
- (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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.