Skip to content

Default Sharing Dialog

Stanislav Osipov edited this page Apr 17, 2020 · 5 revisions

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);

    });
});

Simple Image Sharing

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:

DefaultSharingDialog

Share a file or video

For the non-image sharing (video, pdf, files), you can save the file on the disc and then assign file URL using the AddUrl method of the ISN_UIActivityViewController

About

Foundation

AV Foundation

App Tracking Transparency

Game Kit

Store Kit

UI Kit

Social

Replay Kit

Contacts

AVKit

Photos

App Delegate

User Notifications

MediaPlayer

Core Location

AdSupport

EventKit

CloudKit

Authentication Services

XCode

Knowledge Base

Clone this wiki locally