I am developing a flutter app that connects the app to the boat VCU through Wi-Fi. In the iOS version of the mobile app, when the device connects to a Wi-Fi network, iOS assumes that all network traffic should route through Wi-Fi. As the connected Wi-Fi network has no internet access, iOS prompts the user with the options: "Use Mobile Data" or "Keep Trying Wi-Fi."
If the user selects "Keep Trying Wi-Fi," mobile data will not be used by other apps on the phone.
If the user selects "Use Mobile Data," the app switches to mobile data while remaining connected to the Wi-Fi network (VCU) without any issues. The issue is we need to find a way to prevent showing that prompt and instead handle this through code. After connecting to VCU, the mobile network is available for a few second but then it switches to wifi and no internet! I checked all the online documentation but there is not any solution for it. So, I need to stay connect to vcc and other apps use mobile data. I tried WiFiForIoTPlugin.forceWifiUsage(false); but didn't work. I tried adding delay that also didn't work. This is the function in my code that handles connecting to Wi-fI: Future<void> connectToWifi() async {
try {
if (Platform.isAndroid) {
isConnected = await WiFiForIoTPlugin.connect(
_vesselData['ssid'],
password: _vesselData['passphrase'],
security: NetworkSecurity.WPA,
// Enable Internet access
withInternet: false,
isHidden: true,
timeoutInSeconds: 10,
joinOnce: true,
);
// Force Android to treat Wi-Fi as the primary network using
await WiFiForIoTPlugin.forceWifiUsage(true);
} else if (Platform.isIOS){
isConnected = await WiFiForIoTPlugin.connect(
_vesselData['ssid'],
password: _vesselData['passphrase'],
security: NetworkSecurity.WPA,
isHidden: true,
timeoutInSeconds: 10,
// Ensures the connection remains persistent, preventing the system from disconnecting the device.
joinOnce: false,
);
}
if (isConnected) {
log("Connected to ${_vesselData['ssid']}");
streamData();
} else {
log("Failed to connect to ${_vesselData['ssid']}");
}
} catch (e) {
log("Error: $e");
}
}
I use :Device Model: iPhone 12 Pro Max
iOS Version: iOS 18.3.1
Xcode Version: Xcode 16.2
Mac Version: macOS Sonoma 14.3
Prevent iOS "Use Mobile Data" Prompt When Connected to Wi-Fi Without Internet in Flutter
This is my code:
Future<void> connectToWifi() async {
try {
if (Platform.isAndroid) {
isConnected = await WiFiForIoTPlugin.connect(
_vesselData['ssid'],
password: _vesselData['passphrase'],
security: NetworkSecurity.WPA,
// Enable Internet access
withInternet: false,
isHidden: true,
timeoutInSeconds: 10,
joinOnce: true,
);
// Force Android to treat Wi-Fi as the primary network using
await WiFiForIoTPlugin.forceWifiUsage(true);
} else if (Platform.isIOS){
isConnected = await WiFiForIoTPlugin.connect(
_vesselData['ssid'],
password: _vesselData['passphrase'],
security: NetworkSecurity.WPA,
isHidden: true,
timeoutInSeconds: 10,
// Ensures the connection remains persistent, preventing the system from disconnecting the device.
joinOnce: false,
);
}
if (isConnected) {
log("Connected to ${_vesselData['ssid']}");
streamData();
} else {
log("Failed to connect to ${_vesselData['ssid']}");
}
} catch (e) {
log("Error: $e");
}
}