ios - 获取启用 Wifi 的设备的 Wifi 可用性通知

标签 ios wifi cfnetwork

我有支持 Wifi 的 OBD2 设备适配器。现在我想收到有关带有 OBD2 设备的 Wifi 可用的通知,以便我可以开始与该设备通话并读取数据,而带有 OBD2 设备的 Wifi 不可用。

当设备连接到 OBD2 端口时,wifi 正在广播。我使用了 Reachability 类的示例代码。但是我无法得到适当的通知。

我尝试使用 SimplePingHelper 代码。它适用于主线程,但不能与后台线程一起运行。 SimplePingHelper Source code

SimplePingHelper 代码实际上使用了 Apple 的 SimplePing 示例代码。 SimplePing Code By Apple

你能帮我处理这段与后台线程一起工作的代码吗?或者我可以通过哪些其他方式检查以获得此通知?

最佳答案

`使用 Apple 的默认可达性等级:

This link 下载可达性项目

在您的项目中复制 Reachability.h 和 Reachability.m 文件。

并在应用程序委托(delegate)文件中设置此方法。

-(void)initializeRechabilityObeserver { //在这里更改主机名来更改您监控的服务器 hostReach = [可达性 reachabilityWithHostName: @"www.apple.com http://www.apple.com "]; [hostReach startNotifier]; //[自更新InterfaceWithReachability: hostReach];

internetReach = [Reachability reachabilityForInternetConnection];
[internetReach startNotifier];
//[self updateInterfaceWithReachability: internetReach];

wifiReach = [Reachability reachabilityForLocalWiFi] ;
[wifiReach startNotifier];
//[self updateInterfaceWithReachability: wifiReach];    

关于ios - 获取启用 Wifi 的设备的 Wifi 可用性通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19978903/

相关文章:

iOS 滚动 tableView 可重用单元格重新加载

ios - 手动杀死应用程序时调用哪个方法或远程推送通知到达时如何处理

ios - 如何快速计算 JSON 响应中的 bool 值

Arduino 的 iOS 远程控制

sockets - 如何模拟 “no route to host”错误?

iPhone 应用程序崩溃 - NSZombie 输出问题

linux - rt2870.o/rt2870.ko USB 无线适配器安装问题

linux - 包括/配置/auto.conf.cmd : No such file or directory [Kali Linux]

json - 我怎样才能在shell脚本中curl请求带有 header 的请求

objective-c - 在 Macos High Sierra 上创建和绑定(bind)套接字