NEHotspotConfigurationManagerを使ってWi-fiに接続する(Objective-C版)


iOS11からPublic APIとしてWi-fi接続のAPIが公開されたので
今更ですが記述します。
Objective-Cのサンプルって少なくなりましたね〜

事前にcapabilities->Hotspot ConfigurationをONにしておいてください。

hoge.m
#import <NetworkExtension/NetworkExtension.h>

NEHotspotConfigurationManager *manager = [NEHotspotConfigurationManager sharedManager];
NEHotspotConfiguration *config = [[NEHotspotConfiguration alloc] initWithSSID:@"your ssid" passphrase:@"your passwd" isWEP:NO];
[manager applyConfiguration:config completionHandler:^(NSError *error){
    if(error) {
        NSLog([error localizedDescription]);
    }else{
        NSLog(@"connected");
    }
}];

参考:
https://qiita.com/sushichop/items/3a5682caedf9a8799514
https://dev.classmethod.jp/smartphone/nehotspotconfiguration/