Background: Xamarin Forms app, built from Visual Studio on Windows machine with connection to the Mac.
For data collection, our application should connect to some device over WiFi. WiFi connection is switched programmatically. This is done in platform specific code. "Access WiFi information", "Hotspot Configuration", and "Network Extensions" capabilities are ON.
using( NEHotspotConfigurationManager manager = new NEHotspotConfigurationManager() )
{ using( NEHotspotConfiguration conf = new NEHotspotConfiguration( strSSID, strWpa2Passphrase, false ){ JoinOnce = false } )
{ await manager.ApplyConfigurationAsync( conf ); }
WiFi is switching as expected. It can be verified by System Settings -> WiFi: it shows the iPad gets connected to the external device.
The problem happens here, after WiFi has switched.
using( TcpClient _client = new TcpClient() )
{ await _client.ConnectAsync( ipAddr, nPort ); }
"Network is unreachable" is thrown by ConnectAsync(). It looks like though the WiFi has switched, the network traffic is not routed to that connection for some reason.
I would appreciate any help. Is the app missing any capabilities? Any transport selection or routing? Any security issues that prevent the socket from being created? Any code to invoke before/after WiFi has switched? Maybe, there are other options for switching or selecting WiFi network?
Additional info and details:
- The same code works as expected when the WiFi connection to the external device is established manually via Settings, which indicates the device is functioning properly. In this case WiFi details in Settings have the line "Low Data Mode", while when switched programmatically, no "Data Mode" appears in WiFi details.
- The external device has no Internet capability, if it makes any difference from WiFi switching point of view (in Android it does). The device has WPA2 security.
- The data collection works on other platforms, indicating the external device is OK. It works in iOS as well, but only when WiFi connection is established manually in Settings.
- Switching WiFi manually via Settings is not appropriate option, unless otherwise is absolutely impossible.
- iPad OS version: 15.
Thank you.