What is the best way to check internet connection?

koby1koby1 Member ✭✭

I tried using Xamarin.Essentials:Connectivity and Xam.Plugin.Connectivity.Plugin but I can't figure out a way for iOS to know if the device has really an internet access. One example is, I'm connected to a wifi or my cellular data is open but either of those connections has internet access. I want to inform my app that there's no internet access even though I have an internet connection.

Best Answers

  • koby1koby1 ✭✭
    edited October 1 Accepted Answer

    Hi @ColeX, I changed your code a little bit and I had it working. Instead of https://captive.apple.com I used https://www.google.com

Answers

  • XavierPerseguersXavierPerseguers CHMember ✭✭✭

    I don't use those plugins but I thought I read in the past that they had some "reachability" part, in addition to the "connectivity" part.

    Anyway, basically what you want to do after you know you are "connected", is to try to reach e.g., your API server. If the call succeeds then you really have internet connection, if not then you are in a limited network scenario, such as wifi without internet access or behind a captive portal.

    Maybe your plugin has some way of checking reachability, otherwise you have the trick to do it yourself.

    HTH

  • koby1koby1 Member ✭✭

    Hi @XavierPerseguers, I have also stumbled on that one too. I'll try to do it, see if it will affect the performance of the application. Thanks!

  • koby1koby1 Member ✭✭

    Hi @ColeX, I'm getting a null object when converting NSData to NSString

    I added some code to handle null. The request is success but the "result" is still null.

  • ColeXColeX Member, Xamarin Team Xamurai

    Change the link to https://captive.apple.com , it's the official recommended testing link .

  • koby1koby1 Member ✭✭

    @ColeX I changed the link to https://captive.apple.com and this is what I'm getting

  • ColeXColeX Member, Xamarin Team Xamurai

    Open safari on your device and try to access the website https://captive.apple.com , if you can't access it either, represent that there's no internet access even though you have an internet connection.

  • koby1koby1 Member ✭✭
    edited October 1 Accepted Answer

    Hi @ColeX, I changed your code a little bit and I had it working. Instead of https://captive.apple.com I used https://www.google.com

  • ColeXColeX Member, Xamarin Team Xamurai

    Good , could you mark the solution as answer ?

Sign In or Register to comment.