Reputation: 339
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?
Upvotes: 0
Views: 1413
Reputation: 36
I created a Property which returns CrossConnectivity.Current.IsConnected
in its getter.
Also using the Plugin.Connectivity.CrossConnectivity
NuGet Package.
Upvotes: 0
Reputation: 15410
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
}
Upvotes: 3