3

I am trying to create/add a Hotspot configuration in iOS 11 installed device.

My code is as follows

let hotspotConfig = NEHotspotConfiguration(ssid: "testNetwork")
hotspotConfig.joinOnce = true
NEHotspotConfigurationManager.shared.apply(hotspotConfig) { (configurationError) in
    if configurationError != nil {
      print("error")
      print(configurationError!.localizedDescription)
    } else {
      print("success")
    }        
}

When i try to run the code. Device prompts for permissions as the following:-

"AppName" wants to join Wi-Fi Network "testNetwork"

But on tapping "Join", I am getting the following response

Unable to join the network "testNetwork"

However, on debug console "success" is getting printed.

Please tell me what am i doing wrong.

Pawan Joshi
  • 1,481
  • 2
  • 18
  • 37
  • You're probably seeing success because the configuration was successfully added. That is, it's added like any other "saved" WiFi you may have set up in the past (e.g., your home network, the office wifi). At that point, I can only guess why it failed. My short list would be WiFi signal strength or that the configuration you successful saved had a typo or something invalid. – Rob Oct 02 '17 at 19:28
  • @Rob : Well.. i think i won't be able to create a hotspot from code(which i was hoping i could, hence the attempt). i can only join one. However i am not quite sure. Can i create a hotspot from code, or can only join one ? – Pawan Joshi Oct 10 '17 at 06:26
  • You're right. No, you can't _create_ a new hotspot from code on iOS. NEHotspotConfiguration simply makes it a little easier to connect to a pre-existing WiFi network/WiFi peripheral. – Rob Oct 10 '17 at 15:27
  • @PawanJoshi I have same issue. How can you resolved? – Dipang Nov 08 '17 at 06:22

2 Answers2

1

The network is being added to the device's known network list, making it available to be auto joined. Unless you have a nearby network named "testNetwork" it will always fail to join.

christo16
  • 4,708
  • 5
  • 38
  • 53
-1

Enable Hotspot on App Id configure services

Enable Hotspot on App Id configure services

After Enable Hotspot Configuration

After Enable Hotspot Configuration

Viraj Patel
  • 1,474
  • 8
  • 17