Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Managing the calendar


In this recipe, we will learn how create an event and save it to the device's calendar database.

Getting ready

Create a new Single View Application in Xamarin Studio and name it CalendarEventsApp.

The app we will be creating will output the calendar events of the next 30 days. Make sure you have some calendar events in that period.

How to do it...

Let's create an event and save it to the device's calendar database by performing the following steps:

  1. Add a button on the main view of the controller.

  2. Add the MonoTouch.EventKit namespace in the CalendarEventAppViewController.cs file.

  3. Enter the following code in the ViewDidLoad method:

    this.btnDisplayEvents.TouchUpInside += async (sender, e) => {
      EKAuthorizationStatus status = EKEventStore.GetAuthorizationStatus(EKEntityType.Event);
      EKEventStore evStore = new EKEventStore();
      if (status == EKAuthorizationStatus.NotDetermined)
      {
        if (await evStore.RequestAccessAsync(EKEntityType.Event))
        {
          this.DisplayEvents(evStore...