最近在做一個WiFi相關(guān)的功能的項目疹启,這個框架是iOS9 以后才出來的,在網(wǎng)上查看了資料和根據(jù)自己的摸索蔼卡,然后寫了一個demo喊崖,下面把自己的寫的過程分享給大家,希望可以對你有所幫助雇逞,也請大神支出不足之處:
這個框架的使用大致分為這幾個步驟
- 向蘋果申請使用權(quán)限
- 配置證書文件
- 配置工程
- 代碼實現(xiàn)
申請權(quán)限地址:點擊進入申請
申請周期大約兩到三周蘋果會回復(fù)給你一封郵件荤懂,讓你說明如何使用這個權(quán)限。根據(jù)自己的項目需求如實描述即可
證書如何配置就不此再詳細說明了塘砸。
代碼實現(xiàn):
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableDictionary* options = [[NSMutableDictionary alloc] init];
[options setObject:@"微信連Wi-Fi" forKey:kNEHotspotHelperOptionDisplayName];
dispatch_queue_t queue = dispatch_queue_create("bundle identifier", NULL);
BOOL returnType = [NEHotspotHelper registerWithOptions:options queue:queue handler: ^(NEHotspotHelperCommand * cmd) {
NEHotspotNetwork* network;
NSLog(@"TYPE:? %ld", (long)cmd.commandType);
[cmd createResponse:kNEHotspotHelperResultAuthenticationRequired];
if (cmd.commandType == kNEHotspotHelperCommandTypeEvaluate || cmd.commandType ==kNEHotspotHelperCommandTypeFilterScanList) {
NSLog(@"networkList:? %@", cmd.networkList);
for (network? in cmd.networkList) {
if ([network.SSID isEqualToString:@"ssid"]) {
double signalStrength = network.signalStrength;
NSLog(@"Signal Strength: %f", signalStrength);
[network setConfidence:kNEHotspotHelperConfidenceHigh];
[network setPassword:@"password"];
NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
NSLog(@"Response CMD %@", response);
[response setNetworkList:@[network]];
[response setNetwork:network];
[response deliver];
}
}
}
}];
NSLog(@"result :%d", returnType);
NSArray *array = [NEHotspotHelper supportedNetworkInterfaces];
NSLog(@"wifiArray:%@", array);
NEHotspotNetwork *connectedNetwork = [array lastObject];
NSLog(@"supported Network Interface: %@", connectedNetwork);
}
在項目中還有如下需求:
在應(yīng)用內(nèi)跳轉(zhuǎn)到系統(tǒng)Wi-Fi設(shè)置界面节仿,計算熱門網(wǎng)站的ping值,監(jiān)控當(dāng)前網(wǎng)絡(luò)狀態(tài)掉蔬,發(fā)送通知粟耻,計算使用的流量查近,統(tǒng)計連接Wi-Fi時。
交流qq群:433700706
后續(xù)會介紹的更加詳細挤忙,敬請期待
如有雷同,請告知谈喳。