By default, Xamarin Forms has no way of knowing if a phone has a network connection. But then, why should it? Remember that anything hardware-specific has to be handled by the hardware. This means that we need to use injection.
There is a package on NuGet that allows you to check on connectivity, but it is more interesting to see how we can do it without relying on additional packages.
To start with, we need to decide on the best way to do this. We can use an event or an interface. In general, listening in on an event is simple. The PCL listens for an event generated from the platform.
This was easy. Wow! This is going to be a short chapter!
Except that it isn't. The problem is not so much the change in the network state; it's more in getting the initial state. In this case, we will use the standard interface or the injection method.
Chapter 13. Social Media into the Mix
Social media (such as Facebook, Google+, and Twitter) forms an ever increasingly important role in a user and developer's life. Adding some form of social media in an app is not difficult, but it does pose a few issues. Add into the mix the networks that are not always possible to connect to, and it can be appreciated that things can become messy quickly.
In this chapter, we will:
Learn how to test for network connectivity
Connect to Facebook and Twitter in an app