当用户的设备连接到互联网时,如何在 iOS 上运行方法?

发布于 2024-12-16 02:49:46 字数 143 浏览 6 评论 0原文

在我正在开发的应用程序中,我想在用户的设备连接到互联网时监听事件。我正在考虑这样的用例:如果我的设备当前未连接到互联网(例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一紙繁鸢 2024-12-23 02:49:46

您可以使用 SCNetworkReachabilitySetCallback 设置一个。请参阅 Apple 提供的一个很好的示例,名为 Reachability http://developer .apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

You can set one with SCNetworkReachabilitySetCallback. See a great example by Apple, called Reachability http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

夏夜暖风 2024-12-23 02:49:46

使用可达性类 - 示例为 此处

Reachability* reachability = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
NetworkStatus netStatus = [reachability currentReachabilityStatus];

Use Reachability classes - Sample is here

Reachability* reachability = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
NetworkStatus netStatus = [reachability currentReachabilityStatus];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文