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

Displaying contacts


In this recipe, we will learn how to use the native address book user interface to display contact information.

Getting ready

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

How to do it...

Perform the following steps:

  1. Add a button on the controller.

  2. In the AppDelegate.cs file, add the DisplayContactAppViewController to a navigation controller, as follows:

    window.RootViewController = new UINavigationController(viewController);
  3. Add the following namespaces in the DisplayContactAppViewController.cs file:

    using MonoTouch.AddressBook;
    using MonoTouch.AddressBookUI;
  4. Add the following code in the ViewDidLoad method:

    this.btnDisplayContact.TouchUpInside += (sender, e) => {
      ABAuthorizationStatus status = ABAddressBook.GetAuthorizationStatus();
      NSError error;
      ABAddressBook addressBook = ABAddressBook.Create(out error);
      if (status == ABAuthorizationStatus.NotDetermined)
      {
        addressBook.RequestAccess((g, err) => {
          if (g)
          ...