大佬教程收集整理的这篇文章主要介绍了如何从iOS可达性类更改网络连接通知?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Reachability* reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier]; [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
而我的可达性更改选择器方法如下
- (void)reachabilityChanged:(Nsnotification*)notification { Reachability* reachability = notification.object; if(reachability.currentReachabilityStatus == NotReachablE) NSLog(@"Internet off"); else NSLog(@"Internet on"); }
但是当我关闭我的飞行模式,以及当我在手机中获得网络连接时,我没有收到任何通知.
我错过了什么吗?
@property (nonatomic,assign) BOOL hasInet;
.M
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self setUpRechability]; } -(void)setUpRechability { [[NsnotificationCenter defaultCenter] addObserver:self SELEctor:@SELEctor(handleNetworkChange:) name:kReachabilityChangedNotification object:nil]; reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier]; NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus]; if (remoteHostStatus == NotReachablE) {NSLog(@"no"); self.hasInet-=NO; } else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"wifi"); self.hasInet-=YES; } else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"cell"); self.hasInet-=YES; } } - (void) handleNetworkChange:(Nsnotification *)notice { NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus]; if (remoteHostStatus == NotReachablE) {NSLog(@"no"); self.hasInet-=NO; } else if (remoteHostStatus == ReachableViaWiFi) {NSLog(@"wifi"); self.hasInet-=YES; } else if (remoteHostStatus == ReachableViaWWAN) {NSLog(@"cell"); self.hasInet-=YES; } // if (self.hasInet) { // UIAlertView *alert=[[UIAlertView alloc]initWithtitle:@"Net avail" message:@"" delegate:self cancelButtontitle:OK_EN otherButtontitles:nil,nil]; // [alert show]; // } }
以上是大佬教程为你收集整理的如何从iOS可达性类更改网络连接通知?全部内容,希望文章能够帮你解决如何从iOS可达性类更改网络连接通知?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。