2015-10-06 72 views
4

我已經將NEHotspotHelper合併到我管理圈養網絡的應用程序中,但我遇到了多個問題。我的網絡以高置信度設置在評估狀態後,我沒有收到驗證命令(kNEHotspotHelperCommandTypeAuthenticate)。另外,當設置中的Wi-Fi列表中選擇了SSID時,我的WISPr網絡永遠不會收到評估命令(kNEHotspotHelperCommandTypeEvaluate)。我對WISPr Hotspot的目標是發送一個需要用戶操作的UINotification。任何人知道我失蹤,只要沒有收到kNEHotspotHelperCommandTypeAuthenticate & kNEHotspotHelperCommandTypeEvaluate在這兩種情況下?NEHotspotHelper沒有獲得Authenication/Evaulate命令NetworkExtension

我成立了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]; 
      }  
    }  
} 

}]; 
+0

我有同樣的問題((可設置密碼和註釋的wifi網絡,但在後臺無法進行身份驗證,儘管蘋果聲稱它是可能的也許是雷達時間 – Roma

+0

@Roma待辦事項你有一個類似的代碼行,因爲我發佈,你能分享嗎? – DaveLass

+0

這裏是我的代碼。http://pastebin.com/zNvM4iLr正如我之前說的annotaion和設置密碼的作品,背景認證不((讓我現在當你會看到代碼 - 讓我們一起找出解決方案)) – Roma

回答

3

我的代碼所做的上述第一個錯誤:我期待命令類型評估通過網絡列表枚舉。但是,Evaluate命令實際上正在交付連接的網絡。我得到下面的代碼當前網絡:

   NSArray *array = [NEHotspotHelper supportedNetworkInterfaces]; 

       NEHotspotNetwork *connectedNetwork = [array lastObject]; 

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

然後檢查,看看是否連接列表我的SSID相匹配,如果是這樣我設置網絡的置信度,並提供應對評估:

     [connectedNetwork setConfidence:kNEHotspotHelperConfidenceLow]; 

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

         [response deliver]; 

處理程序給出的下一個命令是Authenticate。我的完整代碼如下所示,我仍在處理驗證後的命令。完整的代碼行是:?

   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); 

     } 

    }]; 
+0

哇!超級酷!!!謝謝你,我會的測試明天,讓你現在我是否能= = – Roma

+0

你設法得到維護狀態被稱爲? – Roma

+0

是的,我得到一個維護命令。在條件中,我檢查是否需要驗證。如果是這樣,我提供的響應包括:[cmd createResponse:kNEHotspotHelperResultAuthenticationRequired] – DaveLass