检测WIfi是否打开

时间:2024-01-07 15:16:26

引入SystemConfiguration库并添加头文件:

#import <SystemConfiguration/SystemConfiguration.h>

代码如下:

    NSArray *ifs = (__bridgeid)CNCopySupportedInterfaces();

    for (NSString *ifnam in ifs) {

        NSDictionary *info = (__bridgeid)CNCopyCurrentNetworkInfo((__bridgeCFStringRef)ifnam);

        //info 保存了所有wifi联网的信息

        if ([info allKeys] == nil) {

            //wifi关闭了

        }

    }