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

Integrating content sharing


In this recipe, we will add the content-sharing functionality in an app. The app will be able to share content through social networks, e-mail, SMS, or AirDrop.

Getting ready

Create a new Single View Application in Xamarin Studio and name it ContentShareApp. The app will work on the simulator, but more sharing targets will be available on an actual device.

How to do it...

Perform the following steps:

  1. Add a button to the controller.

  2. Add the following code in the ContentShareAppViewController class:

    private UIActivityViewController shareController;
    public override void ViewDidLoad ()
    {
      base.ViewDidLoad ();
      this.btnShare.TouchUpInside += async (sender, e) => {
        NSString link = new NSString("http://software.tavlikos.com");
        this.shareController = new UIActivityViewController(new NSObject[] {
          link
        }, null);
        this.shareController.CompletionHandler = this.ActivityCompleted;
    
        await this.PresentViewControllerAsync(this.shareController, true);
      ...