0

How can I check if Internet is available in Xamarin forms shared project.

We can use Cross connectivity plugin in PCL project, can we use the same plugin in shared project as well?

Mars
  • 269
  • 1
  • 3
  • 22

2 Answers2

3

The Cross Connectivity Plugin has been deprecated in favor of Xamarin.Essentials.

First, add the Xamarin.Essentials NuGet Package to both the iOS project and Android project.

Then use it to check connectivity in the shared project:

var current = Connectivity.NetworkAccess;

if (current == NetworkAccess.Internet)
{
    // Connection to internet is available
}
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
  • Do you know if this is supposed to work on an Android Emulator? I have a breakpoint at var current, but it doesn't seem to step into the next line and instead just continues regardless of what I do. – Reza Nov 12 '19 at 01:41
0

I created a Property which returns CrossConnectivity.Current.IsConnected in its getter. Also using the Plugin.Connectivity.CrossConnectivity NuGet Package.

Anthony
  • 3,595
  • 2
  • 29
  • 38