我已注册我的应用程序以使用 Network Extension API 并在评论 here 之后启用后台模式.因此,当用户进入 wifi 设置时,我能够看到范围内的 wifi 列表,但我不知道为什么我无法在所需的 wifi 上设置自定义语句并设置密码。
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys"Try here", kNEHotspotHelperOptionDisplayName, nil];
dispatch_queue_t queue = dispatch_queue_create("com.myapp.ex", 0); // dispatch_get_main_queue()
BOOL isAvailable = [NEHotspotHelper registerWithOptionsptions queue:queue handler: ^(NEHotspotHelperCommand * cmd) {
if(cmd.commandType == kNEHotspotHelperCommandTypeEvaluate || cmd.commandType == kNEHotspotHelperCommandTypeFilterScanList) {
for (NEHotspotNetwork* network in cmd.networkList) {
if ([network.SSID isEqualToString"MySSID"]) {
[network setConfidence:kNEHotspotHelperConfidenceHigh];
[network setPassword"mypassword"];
// This is required
NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
[response setNetwork:network];
[response deliver];
NSLog(@"Confidence set to high for ssid: %@ (%@)\n\n", network.SSID, network.BSSID);
}
}
}
}];
SSID 匹配,因此代码通过所需的 wifi 执行,Try here 应出现在 wifi 设置的 MySSID 下,并且也应应用密码,但两者都不起作用。
知道代码有什么问题吗?谢谢
Best Answer-推荐答案 strong>
我找到了解决方案。我所做的不是在找到 ssid 时创建响应,而是创建一个数组并添加与我的 ssid 匹配的网络,然后调用 createResponse: 设置我的数组中的所有网络:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys"Try here", kNEHotspotHelperOptionDisplayName, nil];
dispatch_queue_t queue = dispatch_queue_create("com.myapp.ex", 0);
BOOL isAvailable = [NEHotspotHelper registerWithOptionsptions queue:queue handler: ^(NEHotspotHelperCommand * cmd) {
NSMutableArray *hotspotList = [NSMutableArray new];
if(cmd.commandType == kNEHotspotHelperCommandTypeEvaluate || cmd.commandType == kNEHotspotHelperCommandTypeFilterScanList) {
for (NEHotspotNetwork* network in cmd.networkList) {
if ([network.SSID isEqualToString"MySSID"]) {
[network setConfidence:kNEHotspotHelperConfidenceHigh];
[network setPassword"mypassword"];
NSLog(@"Confidence set to high for ssid: %@ (%@)\n\n", network.SSID, network.BSSID);
[hotspotList addObject:network];
}
}
NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
[response setNetworkList:hotspotList];
[response deliver];
}
}];
现在我可以在 SSID 名称下看到“Try here”,无需手动添加密码即可加入网络。
关于ios - NEHotspotHelper 尝试在 iOS 上验证网络的问题,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/32605274/
|