WiFiFlutter icon indicating copy to clipboard operation
WiFiFlutter copied to clipboard

fix(wifi_iot): iOS isConnected always true even connection is failed

Open JooYoo opened this issue 1 year ago • 2 comments

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 -> expecting isConnected 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 unwrapping ssid ) and returned as result by comparing itself ( original result(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)

JooYoo avatar Feb 25 '24 16:02 JooYoo

hey @daadu

A friendly question. This PR is already staying here for 3 weeks. Who can I contact to review this PR? 😉

JooYoo avatar Mar 20 '24 07:03 JooYoo

hey @mavyfaby

A friendly question. This PR is already staying here for a month. Who can I contact to review this PR? 😉

JooYoo avatar Mar 28 '24 05:03 JooYoo