Table of Contents

Class ShareSheetManagerV2

Namespace
Uralstech.UShare

Manages the native share sheet plugins.

public sealed class ShareSheetManagerV2 : Singleton<ShareSheetManagerV2>
Inheritance
object
ShareSheetManagerV2

Fields

FileProviderAuthority

The Android FileProvider authority used for sharing. Defaults to "{Application.identifier}.FileProvider", the provider defined by the Android UShare plugin.

public string? FileProviderAuthority

Field Value

string

Properties

AndroidPathHelper

Utility for providing commonly used Android base paths like cacheDir, filesDir, etc.

public AndroidPathHelper AndroidPathHelper { get; }

Property Value

AndroidPathHelper

OnResult

Invoked when the share activity has "completed", with its assigned event ID. This has different meanings in iOS and Android, see remarks for more info.

public UnityEvent<int> OnResult { get; }

Property Value

UnityEvent<int>

Remarks

On iOS, this is invoked after the completion or dismissal of the share event.

On Android, this is invoked only if the user has chosen a target to share to, and is not reliable for all targets.

See Also

Methods

GetDefaultBasePath()

Returns the default shareable directory as defined in the native plugin.

public string GetDefaultBasePath()

Returns

string

Remarks

Files in this directory are not automatically deleted after sharing. Since this is a system cache location, cleanup is optional, but periodically clearing old files may help avoid unnecessary storage use.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareBytes(IReadOnlyList<ReadOnly>, IReadOnlyList<string>, string, ShareOptions?)

Shares multiple separate pieces of data to other apps using the system share sheet.

public ShareSheetManagerV2.EventStatus TryShareBytes(IReadOnlyList<NativeArray<byte>.ReadOnly> data, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)

Parameters

data IReadOnlyList<NativeArray<byte>.ReadOnly>

The data to share.

fileNames IReadOnlyList<string>

The names of the temporary files. Since these are displayed to the user, it's recommended to set human-readable descriptions of the data. Some platforms like iOS may even obfuscate files with non-standard extensions.

contentType string

The MIME type of the combined data; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

ShareSheetManagerV2.EventStatus

An ShareSheetManagerV2.EventStatus object with Success = true if the share sheet activity was presented; false otherwise.

Remarks

This method creates a file for each byte array in a cache folder which can be accessed by the share sheet. The paths to these files are returned in ShareSheetManagerV2.EventStatus. See CreatedFiles for more details.

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

ArgumentException

If fileNames is a different size to data.

TryShareBytes(IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?)

Shares multiple separate pieces of data to other apps using the system share sheet.

public ShareSheetManagerV2.EventStatus TryShareBytes(IReadOnlyList<byte[]> data, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)

Parameters

data IReadOnlyList<byte[]>

The data to share.

fileNames IReadOnlyList<string>

The names of the temporary files. Since these are displayed to the user, it's recommended to set human-readable descriptions of the data. Some platforms like iOS may even obfuscate files with non-standard extensions.

contentType string

The MIME type of the combined data; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

ShareSheetManagerV2.EventStatus

An ShareSheetManagerV2.EventStatus object with Success = true if the share sheet activity was presented; false otherwise.

Remarks

This method creates a file for each byte array in a cache folder which can be accessed by the share sheet. The paths to these files are returned in ShareSheetManagerV2.EventStatus. See CreatedFiles for more details.

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

ArgumentException

If fileNames is a different size to data.

TryShareBytes(int, IReadOnlyList<ReadOnly>, IReadOnlyList<string>, string, ShareOptions?)

Shares multiple separate pieces of data to other apps using the system share sheet.

public ShareSheetManagerV2.EventStatus TryShareBytes(int id, IReadOnlyList<NativeArray<byte>.ReadOnly> data, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)

Parameters

id int

The ID of this share event, returned in OnResult.

data IReadOnlyList<NativeArray<byte>.ReadOnly>

The data to share.

fileNames IReadOnlyList<string>

The names of the temporary files. Since these are displayed to the user, it's recommended to set human-readable descriptions of the data. Some platforms like iOS may even obfuscate files with non-standard extensions.

contentType string

The MIME type of the combined data; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

ShareSheetManagerV2.EventStatus

An ShareSheetManagerV2.EventStatus object with Success = true if the share sheet activity was presented; false otherwise.

Remarks

This method creates a file for each byte array in a cache folder which can be accessed by the share sheet. The paths to these files are returned in ShareSheetManagerV2.EventStatus. See CreatedFiles for more details.

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

ArgumentException

If fileNames is a different size to data.

TryShareBytes(int, IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?)

Shares multiple separate pieces of data to other apps using the system share sheet.

public ShareSheetManagerV2.EventStatus TryShareBytes(int id, IReadOnlyList<byte[]> data, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)

Parameters

id int

The ID of this share event, returned in OnResult.

data IReadOnlyList<byte[]>

The data to share.

fileNames IReadOnlyList<string>

The names of the temporary files. Since these are displayed to the user, it's recommended to set human-readable descriptions of the data. Some platforms like iOS may even obfuscate files with non-standard extensions.

contentType string

The MIME type of the combined data; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

ShareSheetManagerV2.EventStatus

An ShareSheetManagerV2.EventStatus object with Success = true if the share sheet activity was presented; false otherwise.

Remarks

This method creates a file for each byte array in a cache folder which can be accessed by the share sheet. The paths to these files are returned in ShareSheetManagerV2.EventStatus. See CreatedFiles for more details.

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

ArgumentException

If fileNames is a different size to data.

TryShareBytes(int, ReadOnlySpan<byte>, string, string, ShareOptions?)

Shares data to other apps using the system share sheet.

public ShareSheetManagerV2.EventStatus TryShareBytes(int id, ReadOnlySpan<byte> data, string fileName, string contentType, ShareOptions? options = null)

Parameters

id int

The ID of this share event, returned in OnResult.

data ReadOnlySpan<byte>

The data to share.

fileName string

The name of the temporary file. Since this is displayed to the user, it's recommended to set a human-readable description of the data. Some platforms like iOS may even obfuscate files with non-standard extensions.

contentType string

The MIME type of the data; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

ShareSheetManagerV2.EventStatus

An ShareSheetManagerV2.EventStatus object with Success = true if the share sheet activity was presented; false otherwise.

Remarks

This method creates a file for the data in a cache folder which can be accessed by the share sheet. The path to this file is returned in ShareSheetManagerV2.EventStatus. See CreatedFiles for more details.

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareBytes(ReadOnlySpan<byte>, string, string, ShareOptions?)

Shares data to other apps using the system share sheet.

public ShareSheetManagerV2.EventStatus TryShareBytes(ReadOnlySpan<byte> data, string fileName, string contentType, ShareOptions? options = null)

Parameters

data ReadOnlySpan<byte>

The data to share.

fileName string

The name of the temporary file. Since this is displayed to the user, it's recommended to set a human-readable description of the data. Some platforms like iOS may even obfuscate files with non-standard extensions.

contentType string

The MIME type of the data; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

ShareSheetManagerV2.EventStatus

An ShareSheetManagerV2.EventStatus object with Success = true if the share sheet activity was presented; false otherwise.

Remarks

This method creates a file for the data in a cache folder which can be accessed by the share sheet. The path to this file is returned in ShareSheetManagerV2.EventStatus. See CreatedFiles for more details.

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareFile(int, string, string, ShareOptions?)

Shares a file to other apps using the system share sheet.

public bool TryShareFile(int id, string path, string contentType, ShareOptions? options = null)

Parameters

id int

The ID of this share event, returned in OnResult.

path string

The path to the file to share.

contentType string

The MIME type of the file's data; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

bool

true if the share sheet activity was presented; false otherwise.

Remarks

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

(Android) Ensure the path is under the scope of the FileProvider; see GetDefaultBasePath() for this plugin's default folder for shareable data.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareFile(string, string, ShareOptions?)

Shares a file to other apps using the system share sheet.

public bool TryShareFile(string path, string contentType, ShareOptions? options = null)

Parameters

path string

The path to the file to share.

contentType string

The MIME type of the file's data; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

bool

true if the share sheet activity was presented; false otherwise.

Remarks

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

(Android) Ensure the path is under the scope of the FileProvider; see GetDefaultBasePath() for this plugin's default folder for shareable data.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareFiles(int, string[], string, ShareOptions?)

Shares multiple files to other apps using the system share sheet.

public bool TryShareFiles(int id, string[] paths, string contentType, ShareOptions? options = null)

Parameters

id int

The ID of this share event, returned in OnResult.

paths string[]

The paths to files to share.

contentType string

The MIME type of the combined data of the files; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

bool

true if the share sheet activity was presented; false otherwise.

Remarks

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

(Android) Ensure the paths are under the scope of the FileProvider; see GetDefaultBasePath() for this plugin's default folder for shareable data.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareFiles(string[], string, ShareOptions?)

Shares multiple files to other apps using the system share sheet.

public bool TryShareFiles(string[] paths, string contentType, ShareOptions? options = null)

Parameters

paths string[]

The paths to files to share.

contentType string

The MIME type of the combined data of the files; see CommonMimeTypes for common MIME types.

options ShareOptions

Additional options for the event.

Returns

bool

true if the share sheet activity was presented; false otherwise.

Remarks

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

(Android) Ensure the paths are under the scope of the FileProvider; see GetDefaultBasePath() for this plugin's default folder for shareable data.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareImage(int, ReadOnlySpan<byte>, string, string, ShareOptions?)

public ShareSheetManagerV2.EventStatus TryShareImage(int id, ReadOnlySpan<byte> image, string fileName, string contentType, ShareOptions? options = null)

Parameters

id int
image ReadOnlySpan<byte>
fileName string
contentType string
options ShareOptions

Returns

ShareSheetManagerV2.EventStatus

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

See Also

TryShareImage(ReadOnlySpan<byte>, string, string, ShareOptions?)

public ShareSheetManagerV2.EventStatus TryShareImage(ReadOnlySpan<byte> image, string fileName, string contentType, ShareOptions? options = null)

Parameters

image ReadOnlySpan<byte>
fileName string
contentType string
options ShareOptions

Returns

ShareSheetManagerV2.EventStatus

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

See Also

TryShareImageIOS(int, ReadOnlySpan<byte>, ShareOptions?)

Shares an image to other apps using the iOS share sheet.

public bool TryShareImageIOS(int id, ReadOnlySpan<byte> image, ShareOptions? options = null)

Parameters

id int

The ID of this share event, returned in OnResult.

image ReadOnlySpan<byte>

The image to share, must be a format supported by UIImage.

options ShareOptions

Additional options for the event.

Returns

bool

true if the share sheet activity was presented; false otherwise.

Remarks

This is an iOS-specific method which shares the given image data directly with the native plugin. The plugin then creates a UIImage and forwards it to the share sheet.

For a multi-platform method that uses this for iOS, see TryShareImage(ReadOnlySpan<byte>, string, string, ShareOptions?)

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than iOS.

TryShareImages(IReadOnlyList<ReadOnly>, IReadOnlyList<string>, string, ShareOptions?)

Equivalent to TryShareBytes(System.Collections.Generic.IReadOnlyList<Unity.Collections.NativeArray<byte>.ReadOnly>,System.Collections.Generic.IReadOnlyList<string>,string,Uralstech.UShare.ShareOptions?), but falls back to TryShareImagesIOS(int,System.Collections.Generic.IReadOnlyList<Unity.Collections.NativeArray<byte>.ReadOnly>,Uralstech.UShare.ShareOptions?) on iOS.

public ShareSheetManagerV2.EventStatus TryShareImages(IReadOnlyList<NativeArray<byte>.ReadOnly> images, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)

Parameters

images IReadOnlyList<NativeArray<byte>.ReadOnly>
fileNames IReadOnlyList<string>
contentType string
options ShareOptions

Returns

ShareSheetManagerV2.EventStatus

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareImages(IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?)

public ShareSheetManagerV2.EventStatus TryShareImages(IReadOnlyList<byte[]> images, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)

Parameters

images IReadOnlyList<byte[]>
fileNames IReadOnlyList<string>
contentType string
options ShareOptions

Returns

ShareSheetManagerV2.EventStatus

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

See Also

TryShareImages(int, IReadOnlyList<ReadOnly>, IReadOnlyList<string>, string, ShareOptions?)

Equivalent to TryShareBytes(int,System.Collections.Generic.IReadOnlyList<Unity.Collections.NativeArray<byte>.ReadOnly>,System.Collections.Generic.IReadOnlyList<string>,string,Uralstech.UShare.ShareOptions?), but falls back to TryShareImagesIOS(int,System.Collections.Generic.IReadOnlyList<Unity.Collections.NativeArray<byte>.ReadOnly>,Uralstech.UShare.ShareOptions?) on iOS.

public ShareSheetManagerV2.EventStatus TryShareImages(int id, IReadOnlyList<NativeArray<byte>.ReadOnly> images, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)

Parameters

id int
images IReadOnlyList<NativeArray<byte>.ReadOnly>
fileNames IReadOnlyList<string>
contentType string
options ShareOptions

Returns

ShareSheetManagerV2.EventStatus

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareImages(int, IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?)

public ShareSheetManagerV2.EventStatus TryShareImages(int id, IReadOnlyList<byte[]> images, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)

Parameters

id int
images IReadOnlyList<byte[]>
fileNames IReadOnlyList<string>
contentType string
options ShareOptions

Returns

ShareSheetManagerV2.EventStatus

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

See Also

TryShareImagesIOS(int, IReadOnlyList<ReadOnly>, ShareOptions?)

Shares multiple images to other apps using the iOS share sheet.

public bool TryShareImagesIOS(int id, IReadOnlyList<NativeArray<byte>.ReadOnly> images, ShareOptions? options = null)

Parameters

id int

The ID of this share event, returned in OnResult.

images IReadOnlyList<NativeArray<byte>.ReadOnly>

The images to share, must be in formats supported by UIImage.

options ShareOptions

Additional options for the event.

Returns

bool

true if the share sheet activity was presented; false otherwise.

Remarks

This is an iOS-specific method which shares the given image data directly with the native plugin. The plugin then creates UIImages and forwards them to the share sheet.

For a multi-platform method that uses this for iOS, see TryShareImages(int, IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?)

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than iOS.

TryShareImagesIOS(int, IReadOnlyList<byte[]>, ShareOptions?)

Shares multiple images to other apps using the iOS share sheet.

public bool TryShareImagesIOS(int id, IReadOnlyList<byte[]> images, ShareOptions? options = null)

Parameters

id int

The ID of this share event, returned in OnResult.

images IReadOnlyList<byte[]>

The images to share, must be in formats supported by UIImage.

options ShareOptions

Additional options for the event.

Returns

bool

true if the share sheet activity was presented; false otherwise.

Remarks

This is an iOS-specific method which shares the given image data directly with the native plugin. The plugin then creates UIImages and forwards them to the share sheet.

For a multi-platform method that uses this for iOS, see TryShareImages(int, IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?)

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than iOS.

TryShareText(int, string, string?)

Shares text to other apps using the system share sheet.

public bool TryShareText(int id, string text, string? title = null)

Parameters

id int

The ID of this share event, returned in OnResult.

text string

The text to share.

title string

Optional title for the share sheet.

Returns

bool

true if the share sheet activity was presented; false otherwise.

Remarks

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.

TryShareText(string, string?)

Shares text to other apps using the system share sheet.

public bool TryShareText(string text, string? title = null)

Parameters

text string

The text to share.

title string

Optional title for the share sheet.

Returns

bool

true if the share sheet activity was presented; false otherwise.

Remarks

Duplicate IDs in successive calls may prevent reliable OnResult invocations in Android.

Exceptions

PlatformNotSupportedException

Thrown if this method is called on a runtime other than Android or iOS.