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.
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.
Perform the following steps:
Add a button to the controller.
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); ...