2

I want to set my wifi hotspot password programmatically for my application so that user don't have to go to the setting menu to check their password.

I am already using NEHotspotNetwork, where it set the password, but here, we need to set the password which is already there in the setting menu for connecting to the network.

It's also helpful if I can get my wifi hotspot password, from the application without jailbreak my device.

g212gs
  • 863
  • 10
  • 26

2 Answers2

0

You just need to use the following code:

WifiConfiguration netConfig = new WifiConfiguration();
netConfig .preSharedKey = "yourpassword";
Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
Logan
  • 13
  • 5
0

Using NEHotspotNetwork function register you can set the password

NEHotspotHelper.register(options: options, queue: queue) { (cmd: NEHotspotHelperCommand) in

            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
            }

Also you can use network configuration profile with the help of Apple Configurator 2 tool for your known network. There you need to setup your wi-fi and then after installing the NCP on your device, It will automatically connect with the mentioned network. But you have to host that file on server cause we can't download profile locally and using local server like GCDServer(tried already.)

Rahul Verma
  • 688
  • 5
  • 17