本文介绍了如何检查是否启用了wifi选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查iPhone上是否启用了wifi选项(但可能iPhone未连接到其中一个wifi网络)。
How to check if wifi option is enabled on the iPhone or not (but maybe iPhone not connected to one of the wifi net).
推荐答案为此,您需要在项目中导入可达性类。
For this you need to import reachability classes in your project.
之后: -
#import "Reachability.h"在您查看DidLoad写: -
In you view DidLoad write:-
- (void)viewDidLoad { Reachability *internetReach = [[Reachability reachabilityForInternetConnection] retain]; [internetReach startNotifer]; Reachability *wifiReach = [[Reachability reachabilityForLocalWiFi] retain]; [wifiReach startNotifer]; NetworkStatus netStatus1 = [internetReach currentReachabilityStatus]; NetworkStatus netStatus2 = [wifiReach currentReachabilityStatus]; if(netStatus1 == NotReachable && netStatus2 == NotReachable) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"This feature requires an internet connection." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView release]; } else {//wifi connection available; } }更多推荐
如何检查是否启用了wifi选项
发布评论