我希望我的应用程序自动检测互联网连接丢失.所以我使用以下代码. - (void)applicationDidBecomeActive:(UIApplication *)application { Reachability *networkReachability = [Reachability reachabilityForInternetConnection]
- (void)applicationDidBecomeActive:(UIApplication *)application { Reachability *networkReachability = [Reachability reachabilityForInternetConnection]; NetworkStatus networkStatus = [networkReachability currentReachabilityStatus]; if (networkStatus == NotReachable) { [Settings hideSpinner]; //Show no internet connectivity dialog. } else { } }
但问题是它不是在不断检查互联网连接.
它仅在应用程序变为活动状态时进行检查.如何在整个应用程序生命周期内持续检查互联网连接,并在互联网自动关闭时发出警告?
1)[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged