【发布时间】:2013-08-28 18:01:29
【问题描述】:
我正在使用 Apple 的 Reachability 示例代码来检测网络连接变化,并想知道一旦应用返回前台,如何获得准确的网络状态。
在我当前可见的 UIViewController 中,我正在注册为 kReachabilityChangedNotification 的观察者(与 Reachability 示例代码相同)并监听 UIApplicationWillEnterForegroundNotification 和 UIApplicationWillResignActiveNotification 事件。
在我当前可见的 UIViewController 中,就在应用挂起之前:
// While the app is in the foreground, I configure SCNetworkReachabilitySetCallback
// At this point, I have lost connectivity.
[reachability startNotifier];
// this returns NotReachable, as expected
NetworkStatus status = [reachability currentReachabilityStatus];
现在暂停应用并更改 wifi 设置(更改网络设置以建立连接)
After app resume: (in the UIApplicationWillEnterForegroundNotification handler)
// this still returns NotReachable even though I now have connectivity.
NetworkStatus status = [reachability currentReachabilityStatus];
对我做的不正确有什么建议吗?
【问题讨论】:
-
看看这个链接,stackoverflow.com/questions/4846822/…,它讨论了应用程序委托方法和重新进入前台。你能展示更多你的代码吗?例如,您的应用程序中哪里有这个?它是您的应用程序委托吗?在它的什么地方?
-
更好地澄清了我的问题。
标签: ios reachability