[英]How to know if the network state is WiFi hotspot on iOS
現在,我可以識別WiFi / 2G / 3G / 4G,但是當狀態為WiFi熱點時, AFNetworkReachabilityManager
或Reachability
也可以將狀態識別為WiFi。 非常感謝,請幫助我達到這一要求。
我找到了正確的方法:
- (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.