WiFiFlutter
WiFiFlutter copied to clipboard
fix(wifi_iot): iOS isConnected always true even connection is failed
BugReproduce:
- On iOS device
- Location Permission is enabled and granted. Performing
final connectedSSID = await WiFiForIoTPlugin.getSSID()
should see the current connectedSSID. - iOS device is already connected to any available wifi.
- provide an unavailable SSID then perform
final isConnected = await WiFiForIoTPlugin.connect(wrongSSID);
-> iOS System dialog is showing to indicate the connection is failed -> expectingisConnected
is [false] but get [true]
RootCause
-
Where: packages/wifi_iot/ios/Classes/SwiftWifiIotPlugin.swift:
private func connect(call: FlutterMethodCall, result: @escaping FlutterResult)
- How: The way to determine isConnected is that, after connect(targetSSID) is performed, then getSSID to get connectedSSID, checking if targetSSID is equal to connectedSSID.
-
What: In the original code base, because of the confused naming, it only unwrapped the connectedSSID ( original
sSSID
, after unwrappingssid
) and returned as result by comparing itself ( originalresult(ssid == sSSID)
). In this case, once the device is already connected to a ssid, getSSID() works correctly, then getSSID() will return the connectedSSID, unwrapping connectedSSID, comparing itself as the result, it will be always true. It leads connect(targetSSID) returns true, even if the connection is actually failed.
Solution
- Renaming the parameter of getSSID closure: sSSID ->
connectedSSID
- Check if targetSSID is equal to connectedSSID:
result(sSSID == connectedSSID)
hey @daadu
A friendly question. This PR is already staying here for 3 weeks. Who can I contact to review this PR? 😉
hey @mavyfaby
A friendly question. This PR is already staying here for a month. Who can I contact to review this PR? 😉