- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有以下代码来确定是否有互联网连接。此代码工作正常。我怎么知道我是否突然失去联系
var reachability:Reachability?
reachability = Reachability()
self.reachability = Reachability.init()
if((self.reachability!.connection) != .none)
{
print("Internet available")
}
可达性类是否具有报告连接断开的功能。如果无法通过可达性来处理该问题,还有什么其他选择
最佳答案
在 AppDelegate/Vc 中声明它
let reachability = Reachability()!
NotificationCenter.default.addObserver(self, selector: #selector(reachabilityChanged(note:)), name: .reachabilityChanged, object: reachability)
do{
try reachability.startNotifier()
}catch{
print("could not start reachability notifier")
}
//
当状态改变时调用这个方法
@objc func reachabilityChanged(note: Notification) {
let reachability = note.object as! Reachability
switch reachability.connection {
case .wifi:
print("Reachable via WiFi")
case .cellular:
print("Reachable via Cellular")
case .none:
print("Network not reachable")
}
}
//
为了避免崩溃不要忘记取消注册
reachability.stopNotifier()
NotificationCenter.default.removeObserver(self, name: .reachabilityChanged, object: reachability)
关于ios - 互联网连接状态快速可达性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50571045/
我正在尝试通过可访问性来覆盖我的基础,以便我的应用程序不会被应用程序商店拒绝。我熟悉 Apple 在示例代码中提供的 Reachability 类。我的问题是,如何最好地实现这一点。我发现检查 WWA
我有一个 TableView,它使用方法调用 retrieveData 从服务器接收数据。我使用 Reachability 来测试用户是否有互联网连接。如果是,则调用 retrieveData。如果不
一个简单的问题:当应用程序被终止或未运行时,是否可以在互联网连接可用时收到消息、通知或类似信息? 出于我的目的,我需要一种方法来同步我的所有通知,因为 APNs 只能发送最后一条消息。 编辑:我想知道
我终于弄明白了如何使用 apple Reachability 文件,这是一件了不起的事情。 我的问题是,因为我有大约 6 个 View ,每个 View 都需要检查我是否已连接到互联网。在我的应用程序
我正在使用 Apple 提供的示例代码来监控可达性 - 但它仍然让我头疼。顺便说一句,我在 iOS 5 上运行。 // Initialise hostReach = [[Reachability re
Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"]; 这条线在设备上运行良好,但在模拟器上我崩溃了:
在我的应用程序中的 appDelegate.m 中,我插入了可达性代码,就像苹果说的那样: -(BOOL)checkInternet { Reachability *r = [Reachability
大家好,我在使用 Apple 的可达性代码时遇到了一些问题。我发现,即使设备正确连接到互联网,最初可达性代码也会发出 1 个错误通知(Networkstatus = NotReachable),然后是
我的 AppDelegate.m 中有以下代码 - NSLog 的结果始终是 (null),因此条件没有可达性永远不会被解雇。我想知道为什么会这样/我做错了什么。 - (BOOL)applicatio
我正在使用 github 上的 Reachability 库,发现 here .我想通过单击按钮来检查设备是否在线。我是 Reachability 的新手,所以据我所知,您必须开始监听更改,然后测试连
我正在使用这个库:https://github.com/tonymillion/Reachability 问题有时出现在我检查以下表达式时:[[[ReachabilityManager sharedM
我对 AFNetorking 的 Reachability 有点迷茫,没有找到很多有用的信息。 我有一个可以登录 Web API 的应用程序。每个 VC 都以某种方式连接到 API,因此每个 VC 都
我了解如何在我的应用程序中测试互联网可达性,但我需要做的是不断监听应用程序范围内的可达性。因此,如果应用程序中任何地方的任何一点连接状态发生变化,我都可以使用react。 我怎样才能实现这样的目标?
我正在开发一个使用网络的 iPhone 应用程序。 iPhone 通过 HTTP 请求与我的服务器通信,应该可以在 WiFi 和 3G 上工作。 我目前使用 NSURLConnection initW
我目前正在使用可达性来检测可用的连接。当什么都没有或有良好的连接时,这很有效。但是,如果我的用户在飞机上拥有自己的 wifi 节点,但没有连接到整个互联网怎么办?我的用户将在 wifi 开启的情况下处
我已经创建了一个方法来检查主机是否可达。我从苹果开发者网站下载了 Reachability 类(.h 和 .m)并导入到我的项目中。我已将 NSString 名称作为 URL(主机名)传递。主机名是
我正在使用这个库在设备上的连接状态发生变化时得到通知。我不明白为什么这不起作用!我正在做的正是我在 github 文档中阅读的内容! 当应用程序启动时,会发布通知,但当我打开设置、打开/关闭飞行模式并
我是 iOS 新手,刚开始使用它。我正在尝试实现网络可达性以检测网络何时断开连接以及何时通过使用第三方类恢复。我能够检测到网络丢失,但我无法检测到网络断开连接后何时恢复。我正在使用以下条件来检查工作正
我用了this检查互联网连接 (WiFi\3G) 是否有效的问题。 它工作得很好,但有一个小问题。 当我关闭互联网时,该应用程序会发出互联网已关闭的警报;但是当我再次打开它时,直到连接确实建立起来,它
我的 Reachability 完全按照此 thread 中的建议工作. 我正在使用 open source Reachability .但是我没有使用 block 而是使用通知,因此该过程与 App
我是一名优秀的程序员,十分优秀!