From b018a1087b1ec3ebe65c200d56b189d8a56101e8 Mon Sep 17 00:00:00 2001 From: YooO Date: Thu, 17 Oct 2024 06:44:51 +0200 Subject: [PATCH] fix(wifi_iot): iOS isConnected always true even connection is failed - synced with master (#407) * fix: ios isConnected always true --- .../ios/Classes/SwiftWifiIotPlugin.swift | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/wifi_iot/ios/Classes/SwiftWifiIotPlugin.swift b/packages/wifi_iot/ios/Classes/SwiftWifiIotPlugin.swift index 2c1400f1..5638700a 100755 --- a/packages/wifi_iot/ios/Classes/SwiftWifiIotPlugin.swift +++ b/packages/wifi_iot/ios/Classes/SwiftWifiIotPlugin.swift @@ -124,14 +124,7 @@ public class SwiftWifiIotPlugin: NSObject, FlutterPlugin { let sPassword = (call.arguments as? [String : AnyObject])?["password"] as? String? ?? nil let bJoinOnce = (call.arguments as? [String : AnyObject])?["join_once"] as! Bool? let sSecurity = (call.arguments as? [String : AnyObject])?["security"] as! String? - - // print("SSID : '\(sSSID)'") - // print("PASSWORD : '\(sPassword)'") - // print("JOIN_ONCE : '\(bJoinOnce)'") - // if (bJoinOnce) { - // print("The network will be forgotten!") - // } - // print("SECURITY : '\(sSecurity)'") + if #available(iOS 11.0, *) { let configuration = initHotspotConfiguration(ssid: sSSID, passphrase: sPassword, security: sSecurity) configuration.joinOnce = bJoinOnce ?? false @@ -142,19 +135,19 @@ public class SwiftWifiIotPlugin: NSObject, FlutterPlugin { result(false) return } - this.getSSID { (sSSID) -> () in + this.getSSID { (connectedSSID) -> () in if (error != nil) { if (error?.localizedDescription == "already associated.") { - print("Connected to '\(sSSID ?? "")'") + print("Connected to '\(connectedSSID ?? "")'") result(true) } else { print("Not Connected") result(false) } - } else if let ssid = sSSID { - print("Connected to " + ssid) - // ssid check is required because if wifi not found (could not connect) there seems to be no error given - result(ssid == sSSID) + } else if let connectedSSID = connectedSSID { + print("Connected to " + connectedSSID) + // Emit result of [isConnected] by checking if targetSSID is the same as connectedSSID. + result(sSSID == connectedSSID) } else { print("WiFi network not found") result(false)