Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkConnectivity always return none on iOS 15.4 #852

Closed
AliRezaBeitari opened this issue May 2, 2022 · 34 comments
Closed

checkConnectivity always return none on iOS 15.4 #852

AliRezaBeitari opened this issue May 2, 2022 · 34 comments
Labels
bug Something isn't working connectivity_plus Connectivity Plus Hacktoberfest Issues taking part in Hacktoberfest ios

Comments

@AliRezaBeitari
Copy link

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 AliRezaBeitari added the bug Something isn't working label May 2, 2022
@levi956
Copy link

levi956 commented May 7, 2022

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

@AlirezaDaryani
Copy link

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

@huangsir0
Copy link

any update?

@elyssaDev
Copy link

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

@adminant
Copy link

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

@twittergadungan
Copy link

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)

@felipecastrosales
Copy link

this issue persist.

@azataiot
Copy link

Having the same issue......

@adminant
Copy link

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

@inshaf
Copy link

inshaf commented Aug 25, 2022

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

@doriansabo
Copy link

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;
  }

@MorosophDude
Copy link

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;
        }
      }
      ...

@mhadaily mhadaily added the Hacktoberfest Issues taking part in Hacktoberfest label Sep 28, 2022
@abeerrizvi
Copy link

The issue persists, any fix???

@AliRezaBeitari
Copy link
Author

Unfortunately no updates yet!

@gnassro
Copy link

gnassro commented Feb 9, 2023

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

@SamerOrfali22
Copy link

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

@adminant
Copy link

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

@gmjgh
Copy link

gmjgh commented Apr 25, 2023

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.

@RogerBrusamarello
Copy link

Any updates in this topic?

@mkbsugita
Copy link

same issue!

@mkbsugita
Copy link

on 3.1.2 and 4.0.2

@mkbsugita
Copy link

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 ...

@github-actions
Copy link

github-actions bot commented Sep 7, 2023

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 github-actions bot added the Stale label Sep 7, 2023
@MorosophDude
Copy link

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

@felipecastrosales
Copy link

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.

@github-actions github-actions bot removed the Stale label Sep 8, 2023
@crazy-diya
Copy link

same here? Is there any solution?

@prabakaranios
Copy link

Same issue here? any solution or any alternate package.

@syedarsalankazmi
Copy link

syedarsalankazmi commented Nov 30, 2023

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

@Nicoeevee
Copy link

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)

@llorz-o
Copy link

llorz-o commented Jan 22, 2024

iPhone 15
ios 17
same problem, any update?

@emrszr

This comment was marked as off-topic.

@joafc96

This comment was marked as off-topic.

@miquelbeltran
Copy link
Member

Hey all, there is a PR in progress here: #2599 with changes related on how connectivity type is returned by the plugins.
I'd like to know if this issue can be fixed with it.
Please feel free to test it and leave your feedback.
Thanks!

@miquelbeltran
Copy link
Member

miquelbeltran commented Mar 28, 2024

As per today, the plugin works correctly on iOS, including simulators:

image

If anyone is still facing issues, please create a new bug ticket providing the required implementation details, logs, etc.

@fluttercommunity fluttercommunity locked as resolved and limited conversation to collaborators Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working connectivity_plus Connectivity Plus Hacktoberfest Issues taking part in Hacktoberfest ios
Projects
None yet
Development

No branches or pull requests