I'm working on something that will not need to be on the App store, so I have no issues with using private APIs to meet my needs
I'm trying to use the MobileWiFi. framework to read the RSSI value for the wireless network the phone is currently connected to. I've included the
https://github.com/Cykey/ios-reversed-headers/tree/c613e45f3ee5ad9f85ec7d43906cf69ee812ec6a/MobileWiFi` headers and used a bridging header to include them in my swift project and wrote the code as follows. Please excuse me, I am a newbie.
import SystemConfiguration.CaptiveNetwork
typealias _WiFiManagerClientCreate = @convention(c) (CFAllocator, CInt) -> UnsafeRawPointer
typealias _WiFiManagerClientCopyDevices = @convention(c) (UnsafeRawPointer) -> CFArray
typealias _WiFiDeviceClientCopyProperty = @convention(c) (UnsafeRawPointer, CFString) -> CFPropertyList
if let libHandle = dlopen (Paths.ipConfiguration, RTLD_LAZY) {
result = libHandle.debugDescription
let _createManagerPtr = dlsym(libHandle, "WiFiManagerClientCreate")
let _clientCopyDevicesPtr = dlsym(libHandle, "WiFiManagerClientCopyDevices")
let _clientCopyPropertyPtr = dlsym(libHandle, "WiFiDeviceClientCopyProperty")
if (_createManagerPtr != nil) && (_clientCopyDevicesPtr != nil) && (_clientCopyPropertyPtr != nil) {
let _createManager = unsafeBitCast(_createManagerPtr, to: _WiFiManagerClientCreate.self)
let _clientCopyDevices = unsafeBitCast(_clientCopyDevicesPtr, to: _WiFiManagerClientCopyDevices.self)
let _clientCopyProperty = unsafeBitCast(_clientCopyPropertyPtr, to: _WiFiDeviceClientCopyProperty.self)
let manager = _createManager(kCFAllocatorDefault, 0)
let devices = _clientCopyDevices(manager)
let client = CFArrayGetValueAtIndex(devices, 0)
let data = _clientCopyProperty(client!, "RSSI" as CFString)
let rssi = CFDictionaryGetValue(data as! CFDictionary, "RSSI_CTL_AGR")
NSLog("RSSI: (rssi)")
}
dlclose(libHandle)
}
Which yields an error fatal error: unexpectedly found nil while unwrapping an Optional value which stems from trying to call _createManager
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…