My App is able to communicate with a range of IP cameras. The cameras identify themselves with a specific SSID pattern. The user will be able to connect using the standard iOS settings App and upon return to my App can then use the features of the camera.
My viewer App ships with a few SDKs that support each camera manufacturer (at the moment 4). Some of the SDKs are not cheap to load and consume a lot of memory / CPU resources, so I will only load /unload the appropriate SDK upon determing the connected camera based on the SSID.
Determining the SSID has been explained in this document:
https://developer.apple.com/library/archive/qa/qa1942/_index.html
... according to which I should use the CoreNetwork set of functions like CNCopyCurrentNetworkInfo.
So, here is my code for detecting the current SSID:
public static func fetchSSIDInfo() -> String {
var currentSSID = ""
if let interfaces = CNCopySupportedInterfaces() {
for i in 0..<cfarraygetcount(interfaces) {<br=""> let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interfaces, i)
let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString)
if unsafeInterfaceData != nil {
let interfaceData = unsafeInterfaceData! as NSDictionary
currentSSID = interfaceData["SSID"] as! String
print ("SSID INFO: actually read SSID from interface: \(currentSSID) ")
} else {
print ("SSID INFO: no interface data available!")
}
}
} else {
print ("SSID INFO: can not copy supported interfaces")
}
return currentSSID
}
The code will be called every 1 second during time of connection and then every 2-5 seconds if a device has been connected.
Here is a sample output:
SSID INFO: no interface data available!
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: can not copy supported interfaces
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: no interface data available!
SSID INFO: no interface data available!
SSID INFO: no interface data available!
SSID INFO: no interface data available!
SSID INFO: no interface data available!
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
SSID INFO: actually read SSID from interface: Sebastian's Wi-Fi Network
You can see the problem. Sometimes, the SSID is detected, sometimes it isn't. The function will be called once a second.
This problem gets worse as soon as I connect a actual camera, then load the SDK, just to unload it a few seconds afterwards (based on the loss of correct SSID):
SSID INFO: actually read SSID from interface: SOME DEVICE 75B
SSID INFO: actually read SSID from interface: SOME DEVICE 75B
SSID INFO: actually read SSID from interface: SOME DEVICE 75B
SSID INFO: no interface data available!
SSID INFO: actually read SSID from interface: SOME DEVICE 75B
SSID INFO: actually read SSID from interface: SOME DEVICE 75B
SSID INFO: actually read SSID from interface: SOME DEVICE 75B
SSID INFO: actually read SSID from interface: SOME DEVICE 75B
Happy to hear suggestions.