NatShare is a lightweight, easy-to-use native sharing API for Unity Engine. NatShare supports images (using a Texture2D
) and media files (using a string
path). Currently, you can save media to the camera roll, open the native sharing UI, and retrieve a thumbnail for a video:
To share an image, you can use the Share
function:
Texture2D image = ...;
NatShare.Share(image);
The Share
function also has an overload for sharing plain text or a media file:
string videoPath = "file://some/path/to/a/media/file.ext";
NatShare.Share(videoPath);
string message = "Happy Birthday!";
NatShare.Share(message);
All sharing functions take a callback parameter. This callback can be used to know when the user has finished the sharing activity:
string videoPath = ...;
NatShare.ShareMedia(videoPath, callback: OnShare);
void OnShare () {
Debug.Log("User shared recording!");
}
You can save images or media files to the camera roll:
// Save a texture to the camera roll
Texture2D image = ...;
NatShare.SaveToCameraRoll(image);
// Now save a media file to the camera roll
string gifPath = ...;
NatShare.SaveToCameraRoll(gifPath);
NatShare also supports generating thumbnails for videos:
string videoPath = ...;
var thumbnail = NatShare.GetThumbnail(videoPath);
// Do stuff with thumbnail...
You can also request the thumbnail at a specific time in the video:
string videoPath = ...;
// Request the thumbnail at 5 seconds
var thumbnail = NatShare.GetThumbnail(videoPath, 5f);
- On Android, NatShare requires API Level 16 and up
- On iOS, NatShare requires iOS 7 and up
- To discuss, report an issue, or request a feature, visit Unity forums or GitHub
- Contact me at olokobayusuf@gmail.com
Thank you very much!