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

Starting phone calls


In this recipe, we will learn how to invoke the native Phone app to allow the user to place a phone call.

Getting ready

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

Note

The native Phone app is not available on the simulator. It is only available on an iPhone device.

How to do it...

Perform the following steps to allow the user to place phone calls:

  1. Add a button on the view of PhoneCallAppViewController.

  2. Add the following code in the ViewDidLoad method:

    this.btnCall.TouchUpInside += (s, e) => {
      NSUrlurl = new NSUrl("tel:+123456789012");
      if (UIApplication.SharedApplication.CanOpenUrl(url))
      {
        UIApplication.SharedApplication.OpenUrl(url);
      }  else
      {
        Console.WriteLine("Cannot open url: {0}", url.AbsoluteString);
      }
    } ;
  3. Compile and run the app on the device. Tap the Call phone number button to start the call. The following screenshot shows the Phone app placing a call:

How it works...

Through the UIApplication.SharedApplication...