当用户的设备连接到互联网时,如何在 iOS 上运行方法?
在我正在开发的应用程序中,我想在用户的设备连接到互联网时监听事件。我正在考虑这样的用例:如果我的设备当前未连接到互联网(例如 iPod touch,而不是在没有 Wi-Fi 的家里),然后它会连接到互联网(即返回家中)。 iOS 中是否有一个事件可以在我的应用程序中监听?
In the app which I am developing, I want to listen for an event when the user's device becomes connected to the internet. I'm thinking about the use case when if my device is not currently connected to the internet (think iPod touch, not at home where there is no wifi), and then it becomes connected to the internet (i.e., returning home). Is there an event in iOS which I can listen to in my app for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
SCNetworkReachabilitySetCallback
设置一个。请参阅 Apple 提供的一个很好的示例,名为 Reachability http://developer .apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.htmlYou can set one with
SCNetworkReachabilitySetCallback
. See a great example by Apple, called Reachability http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html使用可达性类 - 示例为 此处
Use Reachability classes - Sample is here