NatShare is a lightweight, easy-to-use native sharing API for Unity Engine. NatShare supports sharing text, images (using a Texture2D
) and media files (using a string
path). Currently, you can save media to the camera roll and open the native sharing UI:
To share an image, you can use the SharePayload
:
Texture2D image = ...;
using (var payload = new SharePayload())
payload.AddImage(image);
You can share multiple items at once:
using (var payload = new SharePayload()) {
payload.AddText("Happy Birthday!");
payload.AddMedia("/path/to/some/media/file.mp4");
}
Most payloads support a callback argument. This callback will be invoked when the user has finished the sharing activity:
using (var payload = new SharePayload(
completionHandler: () => {
Debug.Log("User shared video!");
}
))
payload.AddMedia("/path/to/some/media/file.mp4")
You can save images or media files to the camera roll with the SavePayload
:
// Save a texture and a media file to the camera roll
Texture2D image = ...;
using (var payload = new SavePayload()) {
payload.AddImage(image);
payload.AddMedia("/path/to/some/media/file.gif");
}
After building an Xcode project from Unity, add the following keys to the Info.plist
file with a good description:
NSPhotoLibraryUsageDescription
NSPhotoLibraryAddUsageDescription
- On Android, NatShare requires API Level 18+
- On iOS, NatShare requires iOS 9+
- To discuss, report an issue, or request a feature, visit Unity forums or GitHub
- Contact me at [email protected]
Thank you very much!