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

Setting up iOS


iOS is very simple to set up and listens for events. The basis for the majority of code is based on the freely available Reachability.cs class from Xamarin (https://github.com/xamarin/monotouch-samples/blob/master/ReachabilitySample/reachability.cs).

This class contains just about everything required to check your connection. In AppDelegate.cs, a small amount of code is needed to get the ConnectionChanged event:

// set up notifications
var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);

// produce notification
MessageEvents.Change += (object s, UIChangedEventArgs ea) =>
{
  if (ea.ModuleName == "Notification")
  {
    var notification = new UILocalNotification
    {
      FireDate = DateTime.Now,
      AlertAction = "Connection changed",
      AlertBody = ea.Info,
    };
    UIApplication.SharedApplication...