NEHotspotNetwork.fetchCurrent is giving nil values everytime

I'm trying to fetch current connected network (WiFi or hotspot or MobileNetwork). I'm using the below code snippet

NEHotspotNetwork.fetchCurrent { hotspotNetwork in
            print("Network Information")
            print(hotspotNetwork?.ssid)
            print(hotspotNetwork?.isSecure ?? true)
            print(hotspotNetwork?.bssid)
            print(hotspotNetwork?.securityType)
            print(hotspotNetwork?.signalStrength)

I'm able to get the wi fi details. but one thing I noticed that it is giving every network as a UnSecure network whether it is password protected or not.How can we differentiate secure network and Unsecure network.

And after some time, all of sudden, it stop giving all the values i.e. for each(ssid, isSecure, bssid, securityType, signalStrength) It gives nil values. Can anyone help me upstanding this. Thanks in advance.

You must request Entitlements from Apple.

MobileTen wrote:

You must request Entitlements from Apple.

No, that’s not right. While Hotspot Helper does, in general, require approval by Apple, access to the current Wi-Fi network does not.


How can we differentiate secure network and Unsecure network.

Based on the securityType property.

The isSecure property is derived from the same underlying info as the securityType property, so you’re not losing anything here.

The reason why this isn’t populated is that NEHotspotNetwork has two roles:

  • It originally started out as a component within the Hotspot Helper subsystem.

  • It then got reused for the fetchCurrent(…) API.

You’ll see different behaviour in these two cases. The canonical example of this is signalStrength, which is only useful in the first case [1]. And while that behaviour is expected, I suspect that isSecure is just an omission. Normally I’d suggest you file a bug about that but, in this case, securityType is altogether more useful.

And after some time, all of sudden, it stop giving all the values

The most obvious explanation is that the device has left the Wi-Fi network. It can and will do that in various circumstances.

If that’s not the case, the next possibility is that your app has lost its location privileges.

If you rule out both of those then I’m out of ideas.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] See iOS Network Signal Strength.

NEHotspotNetwork.fetchCurrent is giving nil values everytime
 
 
Q