Checking for internet connection or wifi connection with reachabilitySwift

TheFuquan

I'm building an iOS app, at some point i needed to check the app's acces to internet, so i used the ReachabilitySwift library.

After some tests, it seems to me that the library only checks if the device has the wifi connected and not having an actual internet connection provided from my router.

lets say i disconnected my router from internet, if my iOS device is connected via wifi to the router, the reachability tells me that we have internet connection where in actuallity my router has no internet.

I tried the reachability with a particular host but still having the same result

var reachability = Reachability.init(hostname: "google.com");

Is the reachability library supposed to give feedback when the wifi connection is lost or the actual internet connection is lost ?

Thank you in advance.

Anand Menon

I have had similar issues with Reachability where I was making web service calls to VPN protected network.

var reachability = Reachability.init(hostname: "google.com"); didnt work for me as it returned true when there is Wifi connection.

I used Alamofire response when a dummy call is made to the server

func networkIsAvailable(available: (Bool, String?) -> Void) {

        var message : String = ""
        DispatchQueue.main.async {
            HUD.show(.progress)
            Alamofire.request(Constants.baseUrl, method: .get, parameters: ["foo": "bar"])
            .responseJSON(completionHandler: { (response) in
                let error = response.result.error as? NSError
                if error?.localizedDescription == networkAlert {
                    message = networkAlert
                    available(false, message)

                } else if error?.code == cannotConnectServerCode || error?.localizedDescription == cannotConnectServerMessage {
                    message = cannotConnectServerMessage
                    available(false, anotherNetworkAlert)

                } else {
                    available(true, nil)
                }
            })
        }
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cordova - Checking WIFI connection to internet

From Dev

checking Internet connection with HttpClient

From Dev

Checking internet connection with Python

From Dev

Android:Checking for Internet Connection

From Dev

Checking Internet connection in WebView

From Dev

checking Internet connection with HttpClient

From Dev

Android:Checking for Internet Connection

From Dev

Checking internet connection with service on android

From Dev

C# checking Internet connection

From Dev

Checking internet connection using Task

From Dev

Checking if the internet connection is lost at runtime

From Dev

Checking internet connection using Task

From Dev

checking internet connection on android programming

From Dev

WiFi Adapter Internet Connection Drop

From Dev

Android - Checking internet connection before starting an intent

From Java

Broadcast receiver for checking internet connection in android app

From Dev

What is wrong with this method of checking for an internet connection?

From Dev

How to perform AsyncTask for checking internet connection

From Dev

Windows Phone 7 checking for Internet Connection

From Dev

How to perform AsyncTask for checking internet connection

From Dev

android checking internet connection when a button is pressed

From Dev

checking the internet connection and display the result in the TextView class

From Dev

Checking Internet Connection without URL test connection using java

From Dev

android 6.0.1 force wifi connection with no internet access

From Dev

Programmatically choosing the Internet connection (WiFi, mobile broadband,...)

From Dev

Cut or limit internet connection to other wifi devices

From Dev

AFNetworking detect when wifi connection without active internet connection

From Dev

internet connection stopped working, but wifi connection looks fine (ubuntu 18.04.2)

From Dev

Internet connection resets (wifi), no device has wifi for moment

Related Related

  1. 1

    Cordova - Checking WIFI connection to internet

  2. 2

    checking Internet connection with HttpClient

  3. 3

    Checking internet connection with Python

  4. 4

    Android:Checking for Internet Connection

  5. 5

    Checking Internet connection in WebView

  6. 6

    checking Internet connection with HttpClient

  7. 7

    Android:Checking for Internet Connection

  8. 8

    Checking internet connection with service on android

  9. 9

    C# checking Internet connection

  10. 10

    Checking internet connection using Task

  11. 11

    Checking if the internet connection is lost at runtime

  12. 12

    Checking internet connection using Task

  13. 13

    checking internet connection on android programming

  14. 14

    WiFi Adapter Internet Connection Drop

  15. 15

    Android - Checking internet connection before starting an intent

  16. 16

    Broadcast receiver for checking internet connection in android app

  17. 17

    What is wrong with this method of checking for an internet connection?

  18. 18

    How to perform AsyncTask for checking internet connection

  19. 19

    Windows Phone 7 checking for Internet Connection

  20. 20

    How to perform AsyncTask for checking internet connection

  21. 21

    android checking internet connection when a button is pressed

  22. 22

    checking the internet connection and display the result in the TextView class

  23. 23

    Checking Internet Connection without URL test connection using java

  24. 24

    android 6.0.1 force wifi connection with no internet access

  25. 25

    Programmatically choosing the Internet connection (WiFi, mobile broadband,...)

  26. 26

    Cut or limit internet connection to other wifi devices

  27. 27

    AFNetworking detect when wifi connection without active internet connection

  28. 28

    internet connection stopped working, but wifi connection looks fine (ubuntu 18.04.2)

  29. 29

    Internet connection resets (wifi), no device has wifi for moment

HotTag

Archive