How to get wifi name for iOS (cannot get wifi name) (valid for pro-test)

1. Code implementation

#import "ViewController.h"
#import <SystemConfiguration/SystemConfiguration.h>
#import <SystemConfiguration/CaptiveNetwork.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   NSString *wifiName =  [self getWifi];
    NSLog(@"%@",wifiName);
}

- (id)getWifi {
    
    
    NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
    id info = nil;
    for (NSString *ifnam in ifs) {
    
    
        info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        if (info && [info count]) {
    
    
            break;
        }
    }
    NSLog(@"%@",info);
    return info[@"SSID"];
}

@end

Print result:
2020-08-05 08:41:07.089798+0800 wifiName[573:112951] { BSSID = "dc:fe:18:69:f:8c"; SSID = "Linxbot_5G"; SSIDDATA = <4c696e78 626f745f 3547 >; } 2020-08-05 08:41:07.090151+0800 wifiName[573:112951] Linxbot_5G




Linxbot_5G为手机当前连接上的wifi名

2. After iOS12, it is required to turn on the wifi switch in the App ID Configuration and Xcode of the developer website

  • Select the idenfify of the current app in the Identifiers of the developer website.
  • Check Access WiFi information in Edit your App ID Configuration. Click save
  • Then regenerate the Profiles (configuration files) of the changed app

Insert picture description here

Insert picture description here
Insert picture description here

3. After ios13, the user is required to authorize the location permission to get the wifi name

ios13 can't get wifi name (SSID) (valid for pro-test)

Guess you like

Origin blog.csdn.net/baidu_40537062/article/details/107806277