plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[connectivity_plus] returns "none" on iOS always

Open mhadaily opened this issue 3 years ago • 40 comments

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

  1. just run

Logs

mhadaily avatar Apr 06 '21 11:04 mhadaily

Same problem here. I don't have an iOS device, but it definitely does not work in the simulator.

gkrawiec avatar Apr 24 '21 17:04 gkrawiec

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.

sgehrman avatar Jun 02 '21 01:06 sgehrman

Same problem here. It always returns "none".

DotSyndicate avatar Jun 03 '21 10:06 DotSyndicate

I am using an iOS Simulator running on iOS 14.5. It shows that the Wifi is on. But still, returns none.

DotSyndicate avatar Jun 03 '21 10:06 DotSyndicate

Thanks for reporting, we will take a look at this shortly.

mhadaily avatar Jun 03 '21 10:06 mhadaily

@sgehrman @DotSyndicate @gkrawiec we have released a new version, can you give it a try?

mhadaily avatar Jun 07 '21 10:06 mhadaily

@mhadaily I tried the new version of the plugin, 1.0.2. It still is returning none on my iOS simulator.

DotSyndicate avatar Jun 07 '21 12:06 DotSyndicate

@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

mhadaily avatar Jun 07 '21 12:06 mhadaily

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.

DotSyndicate avatar Jun 07 '21 12:06 DotSyndicate

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.

mhadaily avatar Jun 07 '21 12:06 mhadaily

Ok. Let's see.

DotSyndicate avatar Jun 07 '21 12:06 DotSyndicate

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: (_, __) {
   }
}

KiSchnelle avatar Jun 10 '21 11:06 KiSchnelle

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.

preetshah21699 avatar Jun 11 '21 07:06 preetshah21699

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.

mhadaily avatar Jun 11 '21 07:06 mhadaily

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.

DotSyndicate avatar Jun 11 '21 09:06 DotSyndicate

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?

varunbhalerao56 avatar Oct 07 '21 04:10 varunbhalerao56

Hey, I'm running into the same problem, not working in the iOS simulator. Using iPhone 12 Pro Max simulator with iOS 15.4

cfanboy avatar May 16 '22 01:05 cfanboy

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.

gorkemunuvar avatar Aug 09 '22 16:08 gorkemunuvar

@mhadaily any update on this?

ristiisa avatar Sep 30 '22 12:09 ristiisa

Just tested back to ^1.4.0. Works in this version. Does not work for ^2.0.0 onward for me.

martin-affinitas avatar Oct 21 '22 03:10 martin-affinitas

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?

alperefesahin avatar Dec 29 '22 18:12 alperefesahin

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.

mhadaily avatar Dec 31 '22 16:12 mhadaily

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

github-actions[bot] avatar Apr 01 '23 00:04 github-actions[bot]

.

willyfromtheblock avatar Apr 01 '23 06:04 willyfromtheblock

looks like it happens only on IOS Simulator devices if so please edit the title

fullflash avatar Apr 03 '23 16:04 fullflash

not true, in my experience, it doesn't work on real iPhone devices either

LunaSquee avatar Apr 03 '23 16:04 LunaSquee

Issue still exists for both simulator and real IOS device. Kindly we need a solution.

Alakeel avatar Apr 11 '23 17:04 Alakeel

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.

gmjgh avatar Apr 25 '23 10:04 gmjgh

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

fmdogan avatar May 02 '23 11:05 fmdogan

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.

Mohamed50 avatar May 10 '23 13:05 Mohamed50