Okay, well like I mentioned, I used CoreLocation on a iOS 14.2 project with the following items configured:
Project Entitlements:
Code Block xml| <key>com.apple.developer.networking.wifi-info</key> |
| <true/> |
| <key>com.apple.external-accessory.wireless-configuration</key> |
| <true/> |
Project Info.plist:
Code Block xml| <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> |
| <string>Gather location updates to get SSID</string> |
| <key>NSLocationWhenInUseUsageDescription</key> |
| <string>Gather location updates to get SSID</string> |
Code Block swift| import NetworkExtension |
| import os |
| import CoreLocation |
|
| class ViewController: UIViewController { |
|
| var locationManger: CLLocationManager? |
|
| override func viewDidLoad() { |
| super.viewDidLoad() |
| startLocationManager() |
| } |
|
| func startLocationManager() { |
|
| guard locationManger == nil else { |
| locationManger?.requestWhenInUseAuthorization() |
| locationManger?.startUpdatingLocation() |
| return |
| } |
|
| locationManger = CLLocationManager() |
| locationManger?.delegate = self |
| locationManger?.desiredAccuracy = kCLLocationAccuracyKilometer |
| locationManger?.requestWhenInUseAuthorization() |
| locationManger?.startUpdatingLocation() |
| } |
|
| @IBAction func testNetwork() { |
| NEHotspotNetwork.fetchCurrent(completionHandler: { (network) in |
| if let unwrappedNetwork = network { |
| let networkSSID = unwrappedNetwork.ssid |
| os_log("Network: %{public}@ and signal strength %d", networkSSID , unwrappedNetwork.signalStrength) |
| } else { |
| os_log("No available network") |
| } |
| }) |
| } |
|
| } |
|
|
| extension ViewController: CLLocationManagerDelegate { |
|
| func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { |
| if let lastLocation = locations.last { |
| ... |
| } |
| } |
|
| func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { |
| /* Detect the CLAuthorizationStatus and enable the capture of associated SSID. */ |
| if status == CLAuthorizationStatus.authorizedAlways || |
| status == CLAuthorizationStatus.authorizedWhenInUse { |
| ... |
| } |
| } |
|
| func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { |
| if let error = error as? CLError, error.code == .denied { |
| ... |
| manager.stopUpdatingLocation() |
| } |
| } |
| } |
|
Notice that this example uses CoreLocation, but as the description mentions, NEDNSSettingsManager or NETunnelProviderManager could be used too.
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com