How to identify connected network is open or Secured in swift?

Viewed 472

As per the requirement, iOS app needs to identify the currently connected networks whether its open or password protected and display an alert message to the user.

I have gone through the link below but could not make it work https://developer.apple.com/documentation/networkextension/nehotspotnetwork/1618930-issecure I have received entitlements from the apple, But could not see any sample project.

I expect the code should be similar to the below (just to make the question clear, not real code)

let network = NEHotspotNetwork() // get the currently connected network
        let isSecured = network.isSecure // get the current security
        print("isSecure \(isSecured)") //printing the security is password protected or not
1 Answers

Few things to consider to achieve this

  1. Request entitlement from apple

  2. Your device target is iOS 14.*

  3. Code below

    if #available(iOS 14.0, *) { NEHotspotNetwork.fetchCurrent { network in if let network = network { print("is secured ((network.isSecure))") } } }

Related