gpt4 book ai didi

ios - NEHotspotHelper 注释未出现

转载 作者:可可西里 更新时间:2023-11-01 06:24:16 26 4
gpt4 key购买 nike

我们试用了新的 NetworkExtension API。我们成功地在我们的应用程序中重新创建了所有步骤。但是,我们有一个问题,我们仍然没有在 Wifi 设置屏幕中看到 SSID 名称下方的自定义注释。我们在 ios 9 Beta 3、xcode 7 beta 3 上。

我们已经成功完成了这些步骤:

  • @note 1 应用程序的 Info.plist 必须包含一个 UIBackgroundModes 数组* 包含“网络身份验证”。

  • @注2* 应用程序必须设置“com.apple.developer.networking.HotspotHelper”* 作为其权利之一。权利的值是一个 bool 值* 值为真。

这是我们在应用程序中的代码。我们正在尝试通过文本“Try Here”注释名称为“Internet”的 SSID。我们得到为 SSID“Internet”调用 setConfidence 方法的日志。然而,我们在 Wifi 选择屏幕中看不到实际的注释。

我们还尝试为 promise 将应用程序名称显示为默认注释的选项对象传递“nil”。但我们也没有看到。我们在调用方法 registerWithOptions() 时得到返回“true”,并且在打开 wifi 设置屏幕时确实得到回调

NSMutableDictionary* options = [[NSMutableDictionary alloc] init]; 
[options setObject:@"Try Here" forKey:kNEHotspotHelperOptionDisplayName];
 dispatch_queue_t queue = dispatch_queue_create("com.myapp.ex", 0);
BOOL returnType = [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:@"Internet"]){
                [network setConfidence:kNEHotspotHelperConfidenceHigh];              
                NSLog(@"Confidance set to high for ssid:%@",network.SSID);
            } 
        }   
    }
}];

=========================

请帮助我们了解我们缺少什么?

最佳答案

我已经实现了以下代码,用于在应用程序中使用“连接到 MyWifi”为 SSID“TP-LINK”验证和注释 Wifi 热点,它工作正常。

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:@"Connect to MyWifi", 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) {
NSLog(@"network name:%@", network.SSID);
if ([network.SSID isEqualToString:@"TP-LINK"]) {
[network setConfidence:kNEHotspotHelperConfidenceHigh];
[network setPassword:@"<wifi-password>"];
[hotspotList addObject:network];
}
}

NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
[response setNetworkList:hotspotList];
[response deliver];
}
}];

注意:要让上面的代码正常工作,

  1. 您需要通过在 networkextension@apple.com 上邮寄它们来获得 apple 的授权访问权限
  2. 获得授权后,您需要创建新的配置文件,您必须在其中添加网络扩展授权(仅当您有权访问时才可用)并在您的 xcode 中使用该配置文件以使其工作。
  3. 在您的 xcode 的授权文件中将授权 com.apple.developer.networking.HotspotHelper 添加到 true enter image description here
  4. 在 Info.plist 中添加 network-authentication key 到 Required background modes 数组 enter image description here希望有所帮助。谢谢

关于ios - NEHotspotHelper 注释未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31704292/

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