plus_plugins
plus_plugins copied to clipboard
[connectivity_plus] returns "none" on iOS always
It works great for Android, but on iOS it always returns "none" and I can't even get my app to start if I follow the setup docs like this...all that happens is I get the splashscreen and then the app closes. EDIT: To clarify, on an emulator the runs, but all I get is a connection status of None so I see my "error" widget all the time. On a device it starts, then closes.
return StreamProvider<ConnectivityStatus>(
create: (BuildContext context) => ConnectivityService().connectionStatusController.stream,
child: MaterialApp(
System info
Issue occurs on: iOS / Android / both Plugin name: latest Plugin version: latest
Steps to Reproduce
- just run
Logs
Same problem here. I don't have an iOS device, but it definitely does not work in the simulator.
One thing I noticed. On Android the listener seems to get called back once when starting up. I was relying on this to set the initial state of the variable. But iOS it only calls the listen if a change happens.
I have a iPhone without a sym card if that matters. It is connect to wifi.
Same problem here. It always returns "none".
I am using an iOS Simulator running on iOS 14.5. It shows that the Wifi is on. But still, returns none.
Thanks for reporting, we will take a look at this shortly.
@sgehrman @DotSyndicate @gkrawiec we have released a new version, can you give it a try?
@mhadaily I tried the new version of the plugin, 1.0.2. It still is returning none on my iOS simulator.
@DotSyndicate can you specify what is your simulator + which ios version and other useful information. I need to replicate this.
Meanwhile, can you also try on a real device? on my end, it works on both simulator and real device for ios 14.6
My simulator is iPhone 12 Pro max, iOS version 14.5. On the real device, it is working. Actually, I don't own the actual device to test it on.
mm, I have run the same simulator on the same iOS version and it seems to work, although on my machine it was a bit slow. I made a video just in case if you are ciruous. https://www.file.io/download/mz615qoGlVCY
let's wait and see if we get still the same issue from others.
Ok. Let's see.
One thing I noticed. On Android the listener seems to get called back once when starting up. I was relying on this to set the initial state of the variable. But iOS it only calls the listen if a change happens.
I have a iPhone without a sym card if that matters. It is connect to wifi.
Iam also running on Iphone 12 pro max ios 14.5 simulator and was using the onConnectivityChanged stream for rebuilding based on the connection status.
It is "stuck" in loading though as u mentioned and on Android the stream emits a result and it works like a charm. Is there a way to also make this happen on ios? Or force an update? I mean iam using checkConnectivity() for now in the loading case but i think it would still be awesome if it works the same on both.
final connectivityProvider = Provider((ref) => Connectivity());
final connectivityStatusProvider = StreamProvider<ConnectivityResult>((ref) {
return ref.watch(connectivityProvider).onConnectivityChanged;
});
class Checker extends ConsumerWidget {
@override
Widget build(BuildContext context, ScopedReader watch) {
final _conState = watch(connectivityStatusProvider);
return _conState.when(data: (connectStatus) {
if (connectStatus == ConnectivityResult.wifi) {
}
}, loading: () {
}, error: (_, __) {
}
}
I am also facing the same issue. I try to check the connectivity status on my iOS simulator. But it doesn't work and always returns none. I am using the listener to get the status.
Thanks for the feedback @KiSchnelle and @preetshah21699 .
@preetshah21699 can you also please tell me what are your iPhone simulator and ios version? I am trying to replicate this error for simulators but it seems it's working for me. trying to create a different more isolated so I can test better. will keep you posted.
I don't know if this will be helpful at all. But I am using the following code to get updates regarding the connectivity status.
import 'dart:async';
import '../Enums/connectivity_status.dart';
import '../globals.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
class ConnectivityService {
StreamController<ConnectivityStatus> connectionStatusController =
StreamController<ConnectivityStatus>();
ConnectivityService() {
Connectivity().onConnectivityChanged.listen(
(ConnectivityResult result) {
connectionStatusController.add(_getStatusFromResult(result));
},
);
}
ConnectivityStatus _getStatusFromResult(ConnectivityResult result) {
try {
switch (result) {
case ConnectivityResult.mobile:
return ConnectivityStatus.Cellular;
case ConnectivityResult.wifi:
return ConnectivityStatus.Wifi;
case ConnectivityResult.none:
return ConnectivityStatus.Offline;
default:
return ConnectivityStatus.Offline;
}
} catch (e, s) {
recordError(e, s);
return null;
}
}
}
The recordError
function is nothing but just to record any errors. The enums just have the values mentioned in the switch case. I don't know why it seemed like a good idea to create a different value for the status at that moment.
Hey, I am running into the same problem, it works perfectly on android, but when using a stream it does not work on iOS. Using iPhone 12 simulator with iOS version 14.5. My build target for ios is 11.0.
@DotSyndicate is the method you are using working for iOS?
Hey, I'm running into the same problem, not working in the iOS simulator. Using iPhone 12 Pro Max simulator with iOS 15.4
Same issue occurs on my iOS simulator.
Future<void> _checkConnectionStatus(ConnectivityResult connectivityStatus) async {
final isConnectedToAnyNetwork = connectivityStatus != ConnectivityResult.none;
if (!isConnectedToAnyNetwork) {
_isConnected = false;
AppLogger.wtf('Not connected to any network.');
} else {
_isConnected = await checkInternetConnection();
}
}
With the code above, at the app startup firstly it always logs 'Not connected to any network.'. But I invoke this function inside onConnectivityChanged.listen
and it works after all.
Anyway, something unexpected.
@mhadaily any update on this?
Just tested back to ^1.4.0. Works in this version. Does not work for ^2.0.0 onward for me.
The same issue I faced. We're going to go 2023 after 2 days and the package needs to be fixed.
my simulator is iPhone 14 pro max, and I use the same implementation as the others. @mhadaily any update?
Hey folks, I'll jump on this task next week. we all have been pretty busy in the last few month and I personally was on vacation for the last 2 weeks.
let's hope to fix this asap next week.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days
.
looks like it happens only on IOS Simulator devices if so please edit the title
not true, in my experience, it doesn't work on real iPhone devices either
Issue still exists for both simulator and real IOS device. Kindly we need a solution.
To workaround the issue, you can add an empty onConnectivityChanged
listener somewhere in your code - after this, the method Connectivity().checkConnectivity()
will return a correct value.
Same happened on Samsung SM-A515F and SM-N986B models. I don't have these phones but i got logs from clients' phones. It was logged as type "none" but somehow it managed to log which requires network connection.
Both checkConnectivity()
and onConnectivityChanged
returned none
After checking @gmjgh comment and adding log to the listeners it looks like in the first call of the listener the state is always none no matter what the real connection state is. The problem here is that the listener needs a couple milliseconds to read the right connection state. Not retuning none all the time. try to await for 200 millisecond before calling the real listener or avoid the first result that comes from the listener.