Default Sharing Dialog

Before you begin

Code Snippets

The ISN_UIActivityViewController is a view controller that you use to offer standard services from your app.

The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.

Your app is responsible for configuring, presenting, and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act. 

The code snippet below will demonstrate how you configure and present the view controller. Few notes about the example below:

  • Image to share that I will use in this example was retrieved via our custom screenshot tool the SA_ScreenUtil. But you may use any approach to get the Readable Texture2D object you want to share.
  • You may also add multiple images if you wish.
  • Option to print an image or assign to contacts will be excluded. This is not a requirement, you may exclude any option you want, or not exclude any options at all. The system available options are listed with ISN_UIActivityType class.
using SA.iOS.Social;
...

SA_ScreenUtil.TakeScreenshot((screenshot) => {

    ISN_UIActivityViewController controller = new ISN_UIActivityViewController();
    controller.SetText("share text");
    controller.AddImage(screenshot);

    controller.ExcludedActivityTypes.Add(ISN_UIActivityType.Print);
    controller.ExcludedActivityTypes.Add(ISN_UIActivityType.AssignToContact);
    controller.Present((result) => {

        if(result.IsSucceeded) {
            Debug.Log("Completed: " + result.Completed);
            Debug.Log("ActivityType: " + result.ActivityType);
        } else {
            Debug.Log("ISN_UIActivityViewController error: " + result.Error.FullMessage);
        }

        SetAPIResult(result);

    });
});

Also, the most simple and most commonly used way of sharing and image will only take 3 lines of code:

using SA.iOS.Social;
...

ISN_UIActivityViewController controller = new ISN_UIActivityViewController();
controller.AddImage((Texture2D)m_currentTexture.texture);
controller.Present((result) => { });

 

The operation result will be similar to the picture below:

ISN_UIActivityType

using SA.iOS.Social
...

public class ISN_UIActivityType
{
        /// <summary>
    /// The object posts the provided content to the user’s wall on Facebook.
    /// </summary>
    public const string PostToFacebook = "com.apple.UIKit.activity.PostToFacebook";

    /// <summary>
    /// The object posts the provided content to the user’s Twitter feed.
    /// </summary>
    public const string PostToTwitter = "com.apple.UIKit.activity.PostToTwitter";

    /// <summary>
    /// The object posts the provided content to the user’s Weibo feed.
    /// </summary>
    public const string PostToWeibo = "com.apple.UIKit.activity.PostToWeibo";

    /// <summary>
    /// The object posts the provided content to the Messages app.
    /// </summary>
    public const string Message= "com.apple.UIKit.activity.Message";

    /// <summary>
    /// The object posts the provided content to a new email message.
    /// </summary>
    public const string Mail = "com.apple.UIKit.activity.Mail";


    /// <summary>
    /// The object prints the provided content.
    /// </summary>
    public const string Print= "com.apple.UIKit.activity.Print";

    /// <summary>
    /// The object posts the provided content to the pasteboard.
    /// </summary>
    public const string CopyToPasteboard = "com.apple.UIKit.activity.CopyToPasteboard";

    /// <summary>
    /// The object assigns the image to a contact.
    /// </summary>
    public const string AssignToContact = "com.apple.UIKit.activity.AssignToContact";

    /// <summary>
    /// The object assigns the image or video to the user’s camera roll.
    /// </summary>
    public const string SaveToCameraRoll = "com.apple.UIKit.activity.SaveToCameraRoll";

    /// <summary>
    /// The object adds the URL to Safari’s reading list
    /// </summary>
    public const string AddToReadingList= "com.apple.UIKit.activity.AddToReadingList";

    /// <summary>
    /// The object posts the provided image to the user’s Flickr account.
    /// </summary>
    public const string PostToFlickr = "com.apple.UIKit.activity.PostToFlickr";

    /// <summary>
    /// The object posts the provided video to the user’s Vimeo account
    /// </summary>
    public const string PostToVimeo = "com.apple.UIKit.activity.PostToVimeo";

    /// <summary>
    /// The object posts the provided content to the user’s Tencent Weibo feed.
    /// </summary>
    public const string PostToTencentWeibo = "com.apple.UIKit.activity.TencentWeibo";

    /// <summary>
    /// The object makes the provided content available via AirDrop.
    /// </summary>
    public const string AirDrop = "com.apple.UIKit.activity.AirDrop";

    /// <summary>
    /// The object opens the content in iBooks.
    /// </summary>
    public const string OpenInIBooks= "com.apple.UIKit.activity.OpenInIBooks";

    /// <summary>
    /// The object opens the content in Pdf.
    /// </summary>
    public const string MarkupAsPDF = "com.apple.UIKit.activity.MarkupAsPDF";
}