'iOS 15.4 Swift, fetchCurrentCompletionHandler for WiFi information

I have been trying to access the WiFi information for the IoT app that I am developing using Flutter. I imported the flutter_iot_wifi 0.0.2 plugin. It works fine with Android and can display the SSID information of the current network. But with my iPhone running iOS 15.4, it cannot access the SSID and returns null. The error I see in the log is -

2022-03-19 15:13:31.443908+0530 Runner[10345:1319958] [] nehelper sent invalid result code [1] for Wi-Fi information request

2022-03-19 15:13:31.453801+0530 Runner[10345:1320167] flutter: current ssid: null

I have added the necessary Location and WiFi permissions through the Entitlements and info.plist. But for some reason still cannot access the WiFi ssid.

Since the CNCopyCurrentNetworkInfo is deprecated, I am trying to modify the code to use fetchCurrentCompletionHandler as mentioned in the Apple documentation. Please help me out here-

if #available(iOS 11.0, *) {
            var ssid: String?
            if let interfaces = CNCopySupportedInterfaces() as NSArray? {
                for interface in interfaces {
                   NEHotspotNetwork.fetchCurrent (completionHandler: (interface)
                     {
                       ssid = interface?.ssid
                       print(ssid)
                       break
                    })}
            return ssid
            }
        }

This above modification shows build error at parameter 'interface' I am passing to completionHandler- Cannot call value of non-function type 'NSArray.Element' (aka 'Any')

What should I do? Any help is appreciated. Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source