【问题标题】:How to know if the network state is WiFi hotspot on iOSiOS上如何知道网络状态是否为WiFi热点
【发布时间】:2017-11-28 08:36:52
【问题描述】:

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

【问题讨论】:

  • detect hotspot enabling in iOS with private api's 的可能重复项。这个问题还包括一个不使用私有 API 的答案。
  • @RemcoBeugels 这个问题是关于检测当前手机上是否启用了热点。我认为 OP 是在询问是否检测当前手机是否连接到热点(与正确的接入点相比)。

标签: ios afnetworking reachability


【解决方案1】:

我找到了正确的方法:

- (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);
}

【讨论】:

    猜你喜欢
    • 2011-03-08
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多