</pre>步骤一: 在appdelegate中加入 notification 监听信号变化<p></p><p></p><p class="p1"></p><pre name="code" class="objc">- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStatusIsChange:) name:kReachabilityChangedNotification object:nil];
}
-(void)networkStatusIsChange:(NSNotification*)notify{
Reachability* reachability=_reachability;
NSString* netStatus;
switch (reachability.currentReachabilityStatus) {
case ReachableViaWiFi:
NSLog(@"这是在Wifi下");
netStatus=@"WIFI";
break;
case ReachableViaWWAN:
NSLog(@"这是在移动网络下");
netStatus=@"WWAN";
break;
case NotReachable:
NSLog(@"无网络");
netStatus=@"NONE";
break;
iOS监听 网络信号变化
最新推荐文章于 2025-05-05 10:37:45 发布