Class ShareSheetManagerV2
Manages the native share sheet plugins.
public sealed class ShareSheetManagerV2 : Singleton<ShareSheetManagerV2>
- Inheritance
-
objectShareSheetManagerV2
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
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
dataIReadOnlyList<NativeArray<byte>.ReadOnly>The data to share.
fileNamesIReadOnlyList<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.
contentTypestringThe MIME type of the combined data; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional 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
fileNamesis a different size todata.
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
dataIReadOnlyList<byte[]>The data to share.
fileNamesIReadOnlyList<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.
contentTypestringThe MIME type of the combined data; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional 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
fileNamesis a different size todata.
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
idintThe ID of this share event, returned in OnResult.
dataIReadOnlyList<NativeArray<byte>.ReadOnly>The data to share.
fileNamesIReadOnlyList<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.
contentTypestringThe MIME type of the combined data; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional 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
fileNamesis a different size todata.
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
idintThe ID of this share event, returned in OnResult.
dataIReadOnlyList<byte[]>The data to share.
fileNamesIReadOnlyList<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.
contentTypestringThe MIME type of the combined data; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional 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
fileNamesis a different size todata.
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
idintThe ID of this share event, returned in OnResult.
dataReadOnlySpan<byte>The data to share.
fileNamestringThe 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.
contentTypestringThe MIME type of the data; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional 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
dataReadOnlySpan<byte>The data to share.
fileNamestringThe 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.
contentTypestringThe MIME type of the data; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional 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
idintThe ID of this share event, returned in OnResult.
pathstringThe path to the file to share.
contentTypestringThe MIME type of the file's data; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional options for the event.
Returns
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
pathstringThe path to the file to share.
contentTypestringThe MIME type of the file's data; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional options for the event.
Returns
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
idintThe ID of this share event, returned in OnResult.
pathsstring[]The paths to files to share.
contentTypestringThe MIME type of the combined data of the files; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional options for the event.
Returns
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
pathsstring[]The paths to files to share.
contentTypestringThe MIME type of the combined data of the files; see CommonMimeTypes for common MIME types.
optionsShareOptionsAdditional options for the event.
Returns
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?)
Equivalent to TryShareBytes(int, ReadOnlySpan<byte>, string, string, ShareOptions?), but falls back to TryShareImageIOS(int, ReadOnlySpan<byte>, ShareOptions?) on iOS.
public ShareSheetManagerV2.EventStatus TryShareImage(int id, ReadOnlySpan<byte> image, string fileName, string contentType, ShareOptions? options = null)
Parameters
idintimageReadOnlySpan<byte>fileNamestringcontentTypestringoptionsShareOptions
Returns
Exceptions
- PlatformNotSupportedException
Thrown if this method is called on a runtime other than Android or iOS.
- See Also
TryShareImage(ReadOnlySpan<byte>, string, string, ShareOptions?)
Equivalent to TryShareBytes(ReadOnlySpan<byte>, string, string, ShareOptions?), but falls back to TryShareImageIOS(int, ReadOnlySpan<byte>, ShareOptions?) on iOS.
public ShareSheetManagerV2.EventStatus TryShareImage(ReadOnlySpan<byte> image, string fileName, string contentType, ShareOptions? options = null)
Parameters
imageReadOnlySpan<byte>fileNamestringcontentTypestringoptionsShareOptions
Returns
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
idintThe ID of this share event, returned in OnResult.
imageReadOnlySpan<byte>The image to share, must be a format supported by
UIImage.optionsShareOptionsAdditional options for the event.
Returns
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
imagesIReadOnlyList<NativeArray<byte>.ReadOnly>fileNamesIReadOnlyList<string>contentTypestringoptionsShareOptions
Returns
Exceptions
- PlatformNotSupportedException
Thrown if this method is called on a runtime other than Android or iOS.
TryShareImages(IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?)
Equivalent to TryShareBytes(IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?), but falls back to TryShareImagesIOS(int, IReadOnlyList<byte[]>, ShareOptions?) on iOS.
public ShareSheetManagerV2.EventStatus TryShareImages(IReadOnlyList<byte[]> images, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)
Parameters
imagesIReadOnlyList<byte[]>fileNamesIReadOnlyList<string>contentTypestringoptionsShareOptions
Returns
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
idintimagesIReadOnlyList<NativeArray<byte>.ReadOnly>fileNamesIReadOnlyList<string>contentTypestringoptionsShareOptions
Returns
Exceptions
- PlatformNotSupportedException
Thrown if this method is called on a runtime other than Android or iOS.
TryShareImages(int, IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?)
Equivalent to TryShareBytes(int, IReadOnlyList<byte[]>, IReadOnlyList<string>, string, ShareOptions?), but falls back to TryShareImagesIOS(int, IReadOnlyList<byte[]>, ShareOptions?) on iOS.
public ShareSheetManagerV2.EventStatus TryShareImages(int id, IReadOnlyList<byte[]> images, IReadOnlyList<string> fileNames, string contentType, ShareOptions? options = null)
Parameters
idintimagesIReadOnlyList<byte[]>fileNamesIReadOnlyList<string>contentTypestringoptionsShareOptions
Returns
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
idintThe ID of this share event, returned in OnResult.
imagesIReadOnlyList<NativeArray<byte>.ReadOnly>The images to share, must be in formats supported by
UIImage.optionsShareOptionsAdditional options for the event.
Returns
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
idintThe ID of this share event, returned in OnResult.
imagesIReadOnlyList<byte[]>The images to share, must be in formats supported by
UIImage.optionsShareOptionsAdditional options for the event.
Returns
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
idintThe ID of this share event, returned in OnResult.
textstringThe text to share.
titlestringOptional title for the share sheet.
Returns
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
textstringThe text to share.
titlestringOptional title for the share sheet.
Returns
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.