use CNCopyCurrentNetworkInfo in iOS today extension

How can i get the current WiFi SSID in my today extension.

For the iOS app i need this CLLocationManager -> requestWhenInUseAuthorization

But this doesn't make sense in my today extension.

Replies

Is this for iOS 13 or 14? In iOS 13 in a container application if requesting access to the associated SSID using CNCopyCurrentNetworkInfo I need to include the following along with receiving location updates with the usage key of requestWhenInUseAuthorization.

The entitlement for Access Wi-Fi Information.
Code Block
<key>com.apple.developer.networking.wifi-info</key>
<true/>


The following code to access the associated SSID with when receiving location updates:
Code Block swift
func associatedSSIDs() -> [String] {
guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {
return []
}
return interfaceNames.compactMap { name in
guard let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String: AnyObject] else {
return nil
}
guard let ssid = info[kCNNetworkInfoKeySSID as String] as? String else {
return nil
}
return ssid
}
}


Not sure how this aligns with a Today Extension.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com