Unable to get WiFi rssi value

I want to create a function which will return the rssi value of currently connected WiFi network on my iPhone. I tried fetching the value from status bar but I guess that support is no longer provided in Swift. I have tried the following solution and other solutions with similar approach but it doesn't seem to work now.

private func wifiStrength() -> Int? {
    let app = UIApplication.shared
    var rssi: Int?

    guard let statusBar = app.value(forKey: "statusBar") as? UIView, let foregroundView = statusBar.value(forKey: "foregroundView") as? UIView else {
        return rssi
    }

    for view in foregroundView.subviews {
        if let statusBarDataNetworkItemView = NSClassFromString("UIStatusBarDataNetworkItemView"), view .isKind(of: statusBarDataNetworkItemView) {
            if let val = view.value(forKey: "wifiStrengthRaw") as? Int {
                //print("rssi: \(val)")
                rssi = val
                break
            }
        }
    }

    return rssi
}

I want to create a function which will return the rssi value of currently connected WiFi network on my iPhone.

You can’t. There is no API for that. Please see iOS Network ****** Strength for details.

I guess that support is no longer provided in Swift.

There never was such support, and in fact the approach used in that code sample (poking in a private view hierarchy) is never a supported way to do anything on iOS. See the section on But what about this code I found on the ’net? at the link above.

So moving on, the question is: why do you want the Wi-Fi ****** strength? See the Network performance section for discussion of why this usually isn’t what you want. Or is the ****** strength desired for a totally different purpose?

Unable to get WiFi rssi value
 
 
Q