gpt4 book ai didi

ios - NEHotspotHelper 问题尝试在 iOS 上验证网络

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:57:46 24 4
gpt4 key购买 nike

我已经为使用 Network Extension API 注册了我的应用程序,并根据评论 here 启用了后台模式.因此,当用户进入 wifi 设置时,我能够看到范围内的 wifis 列表,但我不知道为什么我无法在所需的 wifis 上设置自定义语句并设置密码。

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 registerWithOptions:options 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 下,密码也应该应用, 但两者都不起作用。

知道代码有什么问题吗?谢谢

最佳答案

我找到了一个解决方案。我没有在找到 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 registerWithOptions:options 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com