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

Sending text messages and e-mails


In this recipe, we will learn how to invoke the native Mail and Messaging apps within our own app.

Getting ready

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

How to do it...

Perform the following steps to invoke the apps:

  1. Add two buttons on the view of SendTextAppViewController.

  2. Add the following code in the ViewDidLoad method:

    this.btnSendText.TouchUpInside += (s, e) => {
      NSUrl textUrl = new NSUrl("sms:+123456789");
      if (UIApplication.SharedApplication.CanOpenUrl(textUrl))
      {
        UIApplication.SharedApplication.OpenUrl(textUrl);
      }  else
      {
        Console.WriteLine("Cannot send text message!");
      }
    } ;
    this.btnSendEmail.TouchUpInside += (s, e) => {
      NSUrl emailUrl = new NSUrl("mailto:[email protected]");
      if (UIApplication.SharedApplication.CanOpenUrl(emailUrl))
      {
        UIApplication.SharedApplication.OpenUrl(emailUrl);
      }  else
      {
        Console.WriteLine("Cannot send email message!");
      }
    } ;
  3. Compile and run the app...