NatShare
Search…
⌃K

SharePayload

class NatML.Sharing.SharePayload : IDisposable
The SharePayload is used to share items using the native sharing UI.

Creating the Payload

/// <summary>
/// Create a share payload.
/// </summary>
SharePayload ();
This payload does not require any parameters.

Adding Text

/// <summary>
/// Add plain text to the payload.
/// </summary>
/// <param name="text">Plain text to add.</param>
void AddText (string text);
Add plain text to be shared in the payload.

Adding Images

/// <summary>
/// Add an image to the payload.
/// </summary>
/// <param name="image">Image to add.</param>
void AddImage (Texture2D image);
The AddImage method adds an image to be shared.
Ensure that the added image.isReadable.

Adding Media Files

/// <summary>
/// Add a media file to the payload.
/// </summary>
/// <param name="path">Path to media file to add.</param>
void AddMedia (string path);
The AddMedia method adds a media file at a given path.
This method can be used to add audio, image, and video files.

Sharing the Payload

/// <summary>
/// Share the payload and return the success value.
/// </summary>
/// <returns>Identifier of the app chosen by the user.</returns>
Task<string> Share ();
The Share method sends the payload to the native OS sharing service, where a UI dialog will be presented to the user to select an app. Once the user completes the sharing action, the return task completes with the app ID of the receiving app.
The share task returns null if the user cancels the sharing action.

Disposing the Payload

/// <summary>
/// Dispose the payload and release resources.
/// </summary>
void Dispose ();
Once the payload has been used, it must be disposed.