ios - NEHotspotHelper 未获得 Authenication/Evaulate 命令 NetworkExtension

标签 ios networking captivenetwork wispr

我一直在将 NEHotspotHelper 整合到我管理强制网络的应用程序中,但我遇到了多个问题。在设置为高置信度的网络处于评估状态后,我没有收到身份验证命令 (kNEHotspotHelperCommandTypeAuthenticate)。此外,当在设置的 Wi-Fi 列表中选择 SSID 时,我的 WISPr 网络永远不会收到评估命令(kNEHotspotHelperCommandTypeEvaluate)。我对 WISPr 热点的目标是发送一个需要用户操作的 UINotification。任何人都知道我在这两种情况下没有收到 kNEHotspotHelperCommandTypeAuthenticate 和 kNEHotspotHelperCommandTypeEvaluate 时遗漏了什么?

我在我的应用委托(delegate)中这样设置了 HotspotHelper registerWithOptions:

 NSMutableDictionary* options = [[NSMutableDictionary alloc] init];  
  [options setObject:@"Hotspot" forKey:kNEHotspotHelperOptionDisplayName];/  

  dispatch_queue_t queue = dispatch_queue_create("com.myapp.ex", 0);  
  BOOL returnType = [NEHotspotHelper registerWithOptions:options queue:queue handler: ^(NEHotspotHelperCommand * cmd) {  
  NEHotspotNetwork* network;  
  NSLog(@"COMMAND TYPE:   %ld", (long)cmd.commandType);

     if (cmd.commandType == kNEHotspotHelperCommandTypeEvaluate || cmd.commandType ==kNEHotspotHelperCommandTypeFilterScanList) {  
       for (network  in cmd.networkList) {  

            NSLog(@"COMMAND TYPE After:   %ld", (long)cmd.commandType);

            if ([network.SSID isEqualToString:@"test-WPA-2"]|| [network.SSID isEqualToString:@"WISPr Hotspot"]) {  

              double signalStrength = network.signalStrength;  
              NSLog(@"Signal Strength: %f", signalStrength);  

              [network setConfidence:kNEHotspotHelperConfidenceHigh];  
              [network setPassword:@"myPassword"];  

              NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];  
              NSLog(@"Response CMD %@", response);  

              [response setNetworkList:@[network]];  
              [response setNetwork:network];  
              [response deliver];  
          }    
     }       
}  

}];  

最佳答案

我在上面的代码中犯的第一个错误:我期望命令类型 Evaluate 枚举网络列表。但是,Evaluate 命令实际上是在寻找传递给连接的网络。我使用以下代码获取当前网络:

                NSArray *array = [NEHotspotHelper supportedNetworkInterfaces];

                NEHotspotNetwork *connectedNetwork = [array lastObject];

                NSLog(@"supported Network Interface: %@", connectedNetwork);

然后检查连接列表是否与我的 SSID 匹配,如果匹配,我设置该网络的置信度并将响应传递给 Evaluate:

                        [connectedNetwork setConfidence:kNEHotspotHelperConfidenceLow];

                        //[response setNetworkList:@[network]];
                        [response setNetwork:connectedNetwork];

                        [response deliver];

处理程序给出的下一个命令是身份验证。我的完整代码如下所示,我仍在处理身份验证后的命令。完整的代码行是:

              BOOL returnType = [NEHotspotHelper registerWithOptions:options queue:queue handler: ^(NEHotspotHelperCommand * cmd) {

              NEHotspotNetwork* network;

              if (cmd.commandType ==kNEHotspotHelperCommandTypeFilterScanList) {

                for (network in cmd.networkList) {

                    //need to check against list of directories

                        if ([network.SSID isEqualToString:@"test-WPA-2"]) {

                            NSLog(@"%@", network.SSID);
                            NSLog(@"SSID is in Directory: %@", network.SSID);

                            double signalStrength = network.signalStrength;
                            NSLog(@"Signal Strength: %f", signalStrength);

                            [network setConfidence:kNEHotspotHelperConfidenceLow];
                            [network setPassword:@"password"];


                            NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
                            NSLog(@"Response CMD %@", response);

                            [response setNetworkList:@[network]];
                            [response setNetwork:network];
                            [response deliver];

                            }
                    }
            }
            if (cmd.commandType == kNEHotspotHelperCommandTypeEvaluate) {

                /* *   When a network is joined initially, the state machine enters
                 *   the Evaluating state. In that state, each HotspotHelper receives a
                 *   command of type Evaluate. If one or more helpers indicates that it
                 *   is able to handle the network, the one with the highest confidence
                 *   level is chosen before entering the Authenticating state. As an
                 *   optimization, the first helper to assert a high confidence wins and
                 *   the state machine ignores the other helpers.
                 *
                 *   If no helpers claim the network, the state machine enters the
                 *   Authenticated state.
                 */

                NSArray *array = [NEHotspotHelper supportedNetworkInterfaces];

                NEHotspotNetwork *connectedNetwork = [array lastObject];

                NSLog(@"supported Network Interface: %@", connectedNetwork);

                NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];

                NSLog(@"Response CMD %@", response);

                [connectedNetwork setConfidence:kNEHotspotHelperConfidenceLow];

                //[response setNetworkList:@[network]];
                [response setNetwork:connectedNetwork];

                [response deliver];


           }

           if (cmd.commandType == kNEHotspotHelperCommandTypeAuthenticate) {

            NSLog(@"COMMAND TYPE In Auth ***********:   %ld \n\n\n\n\n\n", (long)cmd.commandType);

            /*
            *   In the Authenticating state, the chosen helper is given a command of type
            *   Authenticate. The helper is expected to perform whatever network
            *   processing is required to make the network available for general
                *   network traffic. If the authentication is successful, the helper
                *   indicates that with a Success result. The state machine enters the
                *   Authenticated state.
                *
                *   On a network that has been authenticated by a helper, the state machine
                *   enters the Maintaining state when the network is joined again, and also
                *   periodically while the system remains associated with the network. In the
                    *   Maintaining state, the helper is expected to perform whatever network
                    *   operations are required to determine if the network is still able to
                        *   carry general network traffic. If that is the case, the helper returns
                        *   Success. If not, and authentication is again required, it returns
                        *   AuthenticationRequired to cause the state machine to re-enter the
                        *   Authenticating state.
                        *
                        *   In the Authenticating state, if the helper determines that it requires
                            *   user interaction to proceed, the helper first arranges to alert
                            *   the user via a UserLocalNotification, then returns a result of
                            *   UIRequired. The state machine enters the PresentingUI state.*/

        }
        if (cmd.commandType == kNEHotspotHelperCommandTypePresentUI) {

            NSLog(@"COMMAND TYPE In Present UI ***********:   %ld \n\n\n\n\n\n", (long)cmd.commandType);

        }

    }]; 

关于ios - NEHotspotHelper 未获得 Authenication/Evaulate 命令 NetworkExtension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32975104/

相关文章:

c# - Ping.SendAsync() 从 0.0.0.0 返回重播,如何获取 ping 地址?

ios - 如何仅在 iOS 中通过蜂窝网络正确发送请求

ios - WiFi 连接通知 (CaptiveNetwork)

android - 从 Android 的强制门户浏览器 (CaptivePortalLogin) 启动默认浏览器

ios - UILabel 根据要显示的文本自动调整大小

ios - 在 iOS 中使用模态视图 Controller 的返回值

java - 从 InputStream 读取到 byte[] 会抛出 IndexOutOfBoundsException

ios - 域的 AFNetworking 可访问性管理器 - 尽管强制门户始终可访问

ios - 如何继承具有 .xib 文件的自定义 View

iphone - 我应该调用 removeFromSuperview 还是 release 就好了?