2017-01-27 75 views
2

我想爲我的應用程序以編程方式設置我的wifi熱點密碼,以便用戶不必到設置菜單檢查其密碼。以編程方式設置wifi熱點密碼

我已經在使用NEHotspotNetwork,它設置了密碼,但是在這裏,我們需要在設置菜單中設置密碼,以便連接到網絡。

這也有幫助,如果我可以得到我的wifi熱點密碼,從應用程序沒有越獄我的設備。

回答

0

你只需要使用下面的代碼:

WifiConfiguration netConfig = new WifiConfiguration(); 
netConfig .preSharedKey = "yourpassword"; 
0

使用NEHotspotNetwork功能寄存器可以設置密碼

NEHotspotHelper.register(選項:選項,隊列:隊列){(CMD :NEHotspotHelperCommand)

  if cmd.commandType == NEHotspotHelperCommandType.filterScanList { 
       //Get all available hotspots 
       var list: [NEHotspotNetwork] = cmd.networkList! 
       //Figure out the hotspot you wish to connect to 
       // let desiredNetwork : NEHotspotNetwork? = getBestScanResult(list) 

       var hotspot = [NEHotspotNetwork]() 

       for network in cmd.networkList! 
       {//check for your network ssid and set password 
         network.setConfidence(.high) 
           network.setPassword("yourpassword") //Set the WIFI password 


          hotspot.append(network) 

       } 


       let response = cmd.createResponse(NEHotspotHelperResult.success) 
       response.setNetworkList(hotspot) 
       response.deliver() } else if cmd.commandType == NEHotspotHelperCommandType.evaluate { 
       if let network = cmd.network { 

let response = cmd.createResponse(NEHotspotHelperResult.success) 
        response.setNetwork(network) 
        response.deliver() //Respond back } 
      } else if cmd.commandType == NEHotspotHelperCommandType.authenticate { 
       //Perform custom authentication and respond back with success 
       // if all is OK 
       let response = cmd.createResponse(NEHotspotHelperResult.success) 
       response.deliver() //Respond back 
      } 

您還可以在Apple Configurator 2的幫助下使用網絡配置文件工具爲您的已知網絡。您需要設置您的Wi-Fi,然後在設備上安裝NCP後,它會自動連接到所提及的網絡。但是您必須將該文件託管在服務器上,因爲我們無法在本地下載配置文件並使用本地服務器(如GCDServer)(已嘗試過)。

相關問題