plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

checkConnectivity always return none on iOS 15.4

Open AliRezaBeitari opened this issue 2 years ago • 33 comments

System info

Platform the Issue occurs on: iOS 15.4 (Simulator) Plugin name: connectivity_plus Plugin version: ^2.3.0

Steps to Reproduce

  1. call await (Connectivity().checkConnectivity())
  2. check the result which is always ConnectivityResult.none
final connectivityResult = await (Connectivity().checkConnectivity());

if (connectivityResult == ConnectivityResult.none) {
    print('no internet'); // the result is always none
}
Flutter doctor output
[✓] Flutter (Channel stable, 2.10.5, on macOS 12.3.1 21E258 darwin-x64, locale en-US)
    • Flutter version 2.10.5 at /Users/beitari/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (2 weeks ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/beitari/Library/Android/sdk
    • Platform android-31, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.66.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (2 available)
    • iPhone 13 (mobile) • 4015B4E1-4D93-4D88-B798-C612A12CCE1D • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 100.0.4896.127

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

AliRezaBeitari avatar May 02 '22 16:05 AliRezaBeitari

getting the same issue, please have you gotten any fix ?

levi956 avatar May 07 '22 20:05 levi956

same issue, new version of simulator respond none to checkConnectivity() method. I think plugin must change in iOS side.

AlirezaDaryani avatar May 10 '22 13:05 AlirezaDaryani

any update?

huangsir0 avatar Jun 21 '22 07:06 huangsir0

I'm seeing it on iOS 15.5 (physical device).

comESK avatar Jun 21 '22 18:06 comESK

Simulator 15.4 and real iPhone 15.1 return 'none' sometimes, not every time. Very frustrating.

adminant avatar Jun 30 '22 13:06 adminant

I have the same issue. I am using connectivity_plus: ^2.3.5 using iOS simulator 15.5 after stopping the internet connection and I reconnect again, it will always return ConnectivityResult.none in some condition ( unfortunately I can't reproduce it)

twittergadungan avatar Jul 12 '22 06:07 twittergadungan

this issue persist.

felipecastrosales avatar Aug 06 '22 01:08 felipecastrosales

Having the same issue......

azataiot avatar Aug 13 '22 19:08 azataiot

Any news? This issue prevents us from using the plugin in production.

adminant avatar Aug 24 '22 22:08 adminant

when listing for "onConnectivityChanged", it gives following 2 result, even though we are connected to WIFI

ConnectivityResult.none ConnectivityResult.wifi

This triggers when we start the app ( even though we didnt change the connectivity ). But when I checked the old plugin ( connectivity: ^3.0.6 ), the "onConnectivityChanged" is not trigger when the app started and it only triggers when we switch the connectivity

inshaf avatar Aug 25 '22 07:08 inshaf

When the wifi and mobile data are OFF, and then mobile data is turned ON the onConnectivityChanged will be called multiple times.

It seems that it is called before there is an actual mobile connection since I try to ping a server every time when the onConnectivityChanged is called to check for a real internet connection, and it throws an error.

A really ugly workaround is to debaunce onConnectivityChanged for 1 second, to avoid those quick false changes.

      final Debouncer _debouncer = Debouncer(milliseconds: 1000);
    _networkConnectivity.onConnectivityChanged.listen((ConnectivityResult result) {
      // Workaround when turning on mobile data
      // The listener will be called before the mobile data is enabled
      // and returning invalid result
      _debouncer.run(() => checkStatus());
    });
    
      Future<bool> checkStatus() async {
    bool isOnline = false;
    try {
      final List<InternetAddress> result = await InternetAddress.lookup('example.com');
      isOnline = result.isNotEmpty && result[0].rawAddress.isNotEmpty;
    } catch (e) {
      isOnline = false;
    }
    return isOnline;
  }

doriansabo avatar Sep 06 '22 17:09 doriansabo

This is what I settled on for onPressed of my Login button (based on the suggestion of @doriansabo )

    try {
      isProcessing(true);
      final connectivityStatus = await Connectivity().checkConnectivity();
      debugPrint(connectivityStatus.name);
      if (connectivityStatus == ConnectivityResult.none) {
        // This logic for checking connectivity status once again after a 5
        // milliseconds delay is required for iOS devices because of:
        // https://github.com/fluttercommunity/plus_plugins/issues/852
        // https://github.com/fluttercommunity/plus_plugins/issues/858
        // TODO: Revert back to previous logic once these tickets are closed
        await Future.delayed(const Duration(microseconds: 5));
        // Delay of 1 microsecond yielded inconsistent result when we tap the
        // login button very fast (right after logging out) and I was too lazy
        // to test for 2, 3, and 4 microsecond
        final newConnectivityStatus = await Connectivity().checkConnectivity();
        debugPrint(newConnectivityStatus.name);
        if (newConnectivityStatus == ConnectivityResult.none) {
          isProcessing(false);
          showSnackBar(
            message: "Please connect to Internet before trying to Login",
            type: SnackBarTypes.Error,
          );
          return;
        }
      }
      ...

MorosophDude avatar Sep 13 '22 10:09 MorosophDude

The issue persists, any fix???

abeerrizvi avatar Nov 25 '22 14:11 abeerrizvi

Unfortunately no updates yet!

AliRezaBeitari avatar Dec 29 '22 19:12 AliRezaBeitari

same problem with version 3.0.2. i am using flutter 3.7.0. i got this problem on iPhone 7 Plus with ios 15.7.3, and iPhone 8 Plus with ios 15.1.0

gnassro avatar Feb 09 '23 08:02 gnassro

the issue still happening flutter version: 3.7.5 ios version: 16.2

SamerOrfali22 avatar Feb 28 '23 07:02 SamerOrfali22

The issue still here, iOS 15.1, the plugin is very unreliable on iOS, we need fix.

adminant avatar Apr 17 '23 13:04 adminant

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

Any updates in this topic?

RogerBrusamarello avatar May 08 '23 19:05 RogerBrusamarello

same issue!

mkbsugita avatar Jun 08 '23 01:06 mkbsugita

on 3.1.2 and 4.0.2

mkbsugita avatar Jun 08 '23 01:06 mkbsugita

make class

import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';

class ConnectivityManager {
  factory ConnectivityManager() {
    return _instance;
  }

  ConnectivityManager._internal();
  static final ConnectivityManager _instance = ConnectivityManager._internal();
  late StreamSubscription<dynamic> subscription;
  ConnectivityResult result = ConnectivityResult.none;

  void init() {
    subscription = Connectivity()
        .onConnectivityChanged
        .listen((ConnectivityResult result) {
      // Got a new connectivity status!
      this.result = result;
    });
  }
}

And initialize in main.dart

ConnectivityManager().init();

and, call

final connectivityResult = ConnectivityManager().result;

/// bla bla ...

mkbsugita avatar Jun 08 '23 01:06 mkbsugita

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 Sep 07 '23 00:09 github-actions[bot]

Looks like this ticket is getting stale. Ahh, here is a comment to prevent it from auto-closing in 15 days.

MorosophDude avatar Sep 07 '23 06:09 MorosophDude

It's really annoying that it closes automatically.

They say that it's not ideal to comment on an issue with comments like: "same problem here", but if we don't comment and/or move it, the issue is automatically closed.

Maybe I'm generalizing too much, but this is an example.

felipecastrosales avatar Sep 07 '23 11:09 felipecastrosales

same here? Is there any solution?

crazy-diya avatar Nov 01 '23 07:11 crazy-diya

Same issue here? any solution or any alternate package.

prabakaranios avatar Nov 17 '23 11:11 prabakaranios

Same here! Did we find a solution yet? for me Its on MacOS Ventura 13.0.1 (22A400)

syedarsalankazmi avatar Nov 30 '23 04:11 syedarsalankazmi

iOS 15.8 iPhone SE

Connection 2: received failure notification Connection 2: failed to connect 1:50, reason -1 Connection 2: encountered error(1:50)

Nicoeevee avatar Dec 11 '23 07:12 Nicoeevee

iPhone 15 ios 17 same problem, any update?

llorz-o avatar Jan 22 '24 03:01 llorz-o