Book Image

Cross-platform UI Development with Xamarin.Forms

By : Paul Johnson
Book Image

Cross-platform UI Development with Xamarin.Forms

By: Paul Johnson

Overview of this book

Table of Contents (22 chapters)
Cross-platform UI Development with Xamarin.Forms
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
In the Beginning…
Index

Connect me up, Scotty


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.