iOS13 无法获取WIFI(SSID)名字的问题

近期在测试公司 APP在iOS13上面的运行情况,发现一个问题,就是实际已经在设置里面连接了WIFI,但是在搜索WIFI名字的时候,搜到的SSID是空的。
查了一通资料,原来iOS13在获取WIFI名的时候,必须先取得定位权限,否则就是nil了。所以给出了如下解决方案。


WWDC19-CNCopyCurrentNetworkInfo().png

1.在需要获取WIFI名的地方导入框架

#import <CoreLocation/CoreLocation.h>

2.设置CLLocationManager,并设置相关Delegate "CLLocationManagerDelegate"

@property (nonatomic, strong) CLLocationManager *locationMagager;

- (CLLocationManager *)locationMagager {
    if (!_locationMagager) {
        _locationMagager = [[CLLocationManager alloc] init];
        _locationMagager.delegate = self;
    }
    return _locationMagager;
}

3.判断系统版本,做不同处理

if (@available(iOS 13, *)) {
        
        if (CLLocationManager.authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {//开启了权限,直接搜索
            
            [self searchWIFIName];
            
        } else if (CLLocationManager.authorizationStatus == kCLAuthorizationStatusDenied) {//如果用户没给权限,则提示
            
            [UIAlertController showAlertInViewController:self withTitle:@"定位权限关闭提示" message:@"你关闭了定位权限,导致无法使用WIFI功能" cancelButtonTitle:@"确定" destructiveButtonTitle:nil otherButtonTitles:nil tapBlock:^(UIAlertController * _Nonnull controller, UIAlertAction * _Nonnull action, NSInteger buttonIndex) {

            }];
            
        } else {//请求权限
            
            [self.locationMagager requestWhenInUseAuthorization];
        }
        
    } else {
        
        [self searchWIFIName];
    }

4.delegate回调

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    
    if (status == kCLAuthorizationStatusAuthorizedWhenInUse) {
        [self searchWIFIName];
    }
}

这样就可以解决iOS13无法获取WIFI名字的问题了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 新闻地址:http://edu.sina.com.cn/zxx/2019-07-09/doc-ihytcitm07...
    中和lxy阅读 498评论 0 0
  • (第20部分) 第九章 欲海沉浮 自这次彻底的酒醉后,高新刚掌握了自己的酒量,结果虽然不令人鼓舞,却也让他感到了...
    明重阅读 333评论 0 4
  • 凭直觉去做事,往往都很惊喜。 前一晚,我辗转反侧,总觉得第二天要做点什么,做一件真正有趣的事。 于是打开微信和百度...
    半个榴莲阅读 306评论 0 0
  • 大家好 ,我是皈依佛门的弟子,皈依佛门是佛教徒四大教之一。四大教,第一是佛教徒,第二印度教, 第三一格兰教, 第四...
    改变自己改变未来_daf3阅读 200评论 0 0
  • 我们开工比较晚,一直延续着春节法定外早放假三天晚上班三天的政策。 老大给大家准备了红包,虽然不多,每人一百,总之有...
    小猪天堂阅读 175评论 0 1