Below is the code I use to get my current WiFi SSID and display it in my app.
I have location permissions set to always, as well as the required Privacy info.plist values. I also have the Access WiFi Information capability added to my project. When I build the app from Xcode to my iPhone (not simulator), it works fine, I can see my WiFi SSID. However, when I distribute the app through Testflight it no longer works, it is returning nothing.
import SystemConfiguration.CaptiveNetwork
private func getWiFiSsid() -> String? {
var ssid: String?
if let interfaces = CNCopySupportedInterfaces() as NSArray? {
for interface in interfaces {
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
break
}
}
}
return ssid
}
Below is a screenshot of the entitlements that I unpackages from the ipa file, showing that I do have the Access WiFi Information set:

Since
CNCopyCurrentNetworkInfois deprecated from iOS 14 (https://developer.apple.com/documentation/systemconfiguration/1614126-cncopycurrentnetworkinfo) consider migrating toNEHotspotNetwork.fetchCurrentand we can use this method with user's authorization to access precise location e.g.:NOTE: you have to set
Access WiFi Informationto YES in your entitlements file ,Privacy - Location Always and When In Use Usage DescriptionandPrivacy - Location When In Use Usage Descriptionin you Info.plist as well.