如何检查是否启用了wifi选项 [英] How To check if wifi option enabled or not

查看:122
本文介绍了如何检查是否启用了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选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆