SavePayload

class NatML.Sharing.SavePayload : IDisposable

The SavePayload is used to save items to the camera roll.

Requesting Permissions

/// <summary>
/// Request permissions to save media to the camera roll.
/// </summary>
static Task<bool> RequestPermissions ();

Before creating a SavePayload, you must ensure that the user has granted your app permissions to write to the camera roll. Use this method to request permissions.

To use this payload on iOS, you must define the NSPhotoLibraryUsageDescription key in your Xcode project's Info.plist file.

To use this payload on Android, you must specify the WRITE_EXTERNAL_STORAGE permission in your app's manifest. You can do so in Player Settings.

Creating the Payload

/// <summary>
/// Create a save payload.
/// </summary>
/// <param name="album">Optional. Album in which items should be saved.</param>
SavePayload (string album = default);

The save payload can be optionally created to save items within a specific album in the camera roll. If the album does not already exist, it will be created.

Saving to a specific album will only work on Android Q or newer.

Adding Images

/// <summary>
/// Add an image to the payload.
/// Note that the image MUST be readable.
/// </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 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.

Saving to the Camera Roll

/// <summary>
/// Save the payload contents to the camera roll.
/// </summary>
/// <returns>Whether the save operation was successfully completed.</returns>
Task<bool> Save ();

The Save method saves the payload contents to the camera roll. The returned tasks completes with a bool indicating whether the save operation was successfully completed.

Disposing the Payload

/// <summary>
/// Dispose the payload and release resources.
/// </summary>
void Dispose ();

Once the payload has been used, it must be disposed.

Last updated