As Sharing feature supports multiple sharing sources (Email, Facebook, SMS, WhatsApp, Twitter), different composers are available to populate data.
Different Composers are available to fill the data for each service. Composers available are
MessageShareComposer - Compose data for sharing via Messaging Service
MailShareComposer - Compose data for sharing via Email Service
FacebookShareComposer - Compose data for sharing via Facebook
WhatsAppShareComposer - Compose data for sharing via WhatsApp
TwitterShareComposer - Compose data for sharing via Twitter
SocialShareSheet - Compose data for sharing via Facebook & Twitter
ShareSheet - Compose data for sharing via all services
Once a composer data is populated, present it with ShowView method to start sharing.
NPBinding.Sharing.ShowView(COMPOSER_INSTANCE, FINISHED_SHARING_CALLBACK);
Create an instance of any composer mentioned above and pass to ShowView
All sharing actions optionally take callback method which will be called once sharing window is closed. A common implementation of callback is as below.
void FinishedSharing (eShareResult _result){Debug.Log("Finished sharing");Debug.Log("Share Result = " + _result);}
For sharing with SMS, you first check if the service is available on target platform.
NPBinding.Sharing.IsMessagingServiceAvailable()
Above returns true if service is available.
For sharing, create MessageShareComposer and fill in the details.
// Create composerMessageShareComposer _composer = new MessageShareComposer();_composer.Body = SMS_BODY_MESSAGE;_composer.ToRecipients = ARRAY_OF_RECIPIENTS;
Open Share window by below code :
NPBinding.Sharing.ShowView(_composer, FinishedSharing);
Above call triggers FinishedSharing Callback once sharing is done.
void FinishedSharing (eShareResult _result){Debug.Log("Finished sharing");Debug.Log("Share Result = " + _result);}
For sharing with Email, you first check if the service is available on target platform.
NPBinding.Sharing.IsMailServiceAvailable()
Above returns true if service is available.
For sharing, create MailShareComposer to fill in the details and pass it to ShowView. MailShareComposer provides option to fill in :
To Receipients List
CC Receipients List
BCC Receipients List
Mail Body
HTML Body (set IsHTMLBody to true if you pass html content in Body parameter)
Attach any type of attachment (attachment type supported or not depends on the sharing service)
Once sharing is finished, FinishedSharing Callback will be called.
MailShareComposer _composer = new MailShareComposer();_composer.Subject = m_mailSubject;_composer.Body = m_plainMailBody;​// Set below to true if the body is HTML_composer.IsHTMLBody = false;​// Send array of receivers if required_composer.ToRecipients = m_mailToRecipients;_composer.CCRecipients = m_mailCCRecipients;_composer.BCCRecipients = m_mailBCCRecipients;​// Add below line if you want to attach screenshot. Else, ignore.// _composer.AttachScreenShot();​// Add below line if you want to attach a file, for ex : image. Else, ignore.// _composer.AddAttachmentAtPath(GET_FULL_IMAGE_PATH, MIMEType.kPNG);​// Use below line if you want to add any other attachment format. Else, ignore.// _composer.AddAttachment(ATTACHMENT_DATA_IN_BYTE_ARRAY, ATTACHMENT_FILE_NAME, MIME_TYPE);​// Show share viewNPBinding.Sharing.ShowView(_composer, FinishedSharing);
MIME_TYPE for some file types are
PNG : image/png or use MIMEType.PNG
PDF : application/pdf or use MIMEType.PDF
ZIP : application/zip
Social Share provides facility to share below types on Facebook & Twitter:
Text Message
URL
Image
Some services won't allow sharing some of the attributes or combined properties above as per their policies. For ex: Facebook won't allow prefilled text in the share dialog. !!!!
// Create share sheetSocialShareSheet _shareSheet = new SocialShareSheet();_shareSheet.Text = m_shareMessage;​// Add below line if you want to share URL_shareSheet.URL = m_shareURL;​// Add below line if you want to share a screenshot_shareSheet.AttachScreenShot();​// Add below line if you want to share an image from a specified path._shareSheet.AttachImageAtPath(IMAGE_PATH);​// Show composerNPBinding.UI.SetPopoverPointAtLastTouchPosition(); // To show popover at last touch point on iOS. On Android, its ignored.NPBinding.Sharing.ShowView(_shareSheet, FinishedSharing);
For sharing, create SocialShareSheet to fill in the details and pass it to ShowView. SocialShareSheet provides option to fill in :
Text message to share
URL to share
Screenshot
Texture
Image at path
Once sharing is finished, FinishedSharing Callback will be called.
// Create share sheetSocialShareSheet _shareSheet = new SocialShareSheet();_shareSheet.Text = m_shareMessage;​// Add below line if you want to share URL_shareSheet.URL = m_shareURL;​// Add below line if you want to share a screenshot_shareSheet.AttachScreenShot();​// Add below line if you want to share an image from a specified path._shareSheet.AttachImageAtPath(IMAGE_PATH);​// Show composerNPBinding.UI.SetPopoverPointAtLastTouchPosition(); // To show popover at last touch point on iOS. On Android, its ignored.NPBinding.Sharing.ShowView(_shareSheet, FinishedSharing);
Some services won't allow more than one data to share. If you are trying to share message and url, ONLY one of those can be shared successfully. This is a limitation of that service and not from the plugin.
This feature allows to share on Facebook alone.
Check availability of the service with :
NPBinding.Sharing.IsFBShareServiceAvailable();
Above returns true if Facebook app is installed and ready to share.
It's not allowed to share pre-filled text as per Facebook Policy.
private void ShareURLOnFB (){// Create share sheetFBShareComposer _composer = new FBShareComposer();_composer.URL = m_shareURL;​// Show composerNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
private void ShareScreenshotOnFB (){// Create composerFBShareComposer _composer = new FBShareComposer();_composer.AttachScreenShot();​// Show share viewNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
private void ShareImageOnFB (){// Create composerFBShareComposer _composer = new FBShareComposer();_composer.Text = m_shareMessage;_composer.AttachImageAtPath(GetImageFullPath());​// Show share viewNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
This feature allows to share on Twitter alone.
Check availability of the service with :
NPBinding.Sharing.IsTwitterShareServiceAvailable();
Above returns true if Twitter app is installed and ready to share.
private void ShareTextMessageOnTwitter (){// Create composerTwitterShareComposer _composer = new TwitterShareComposer();_composer.Text = m_shareMessage;​// Show share viewNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
private void ShareURLOnTwitter (){// Create share sheetTwitterShareComposer _composer = new TwitterShareComposer();_composer.Text = m_shareMessage;_composer.URL = m_shareURL;​// Show composerNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
private void ShareScreenshotOnTwitter (){// Create composerTwitterShareComposer _composer = new TwitterShareComposer();_composer.Text = m_shareMessage;_composer.AttachScreenShot();​// Show share viewNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
private void ShareImageOnTwitter (){// Create composerTwitterShareComposer _composer = new TwitterShareComposer();_composer.Text = m_shareMessage;_composer.AttachImageAtPath(GetImageFullPath());​// Show share viewNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
This feature allows to share on WhatsApp alone.
Check availability of the service with :
NPBinding.Sharing.IsWhatsAppServiceAvailable();
Above returns true if WhatsApp app is installed and ready to share.
private void ShareTextMessageOnWhatsApp (){// Create composerWhatsAppShareComposer _composer = new WhatsAppShareComposer();_composer.Text = m_shareMessage;​// Show share viewNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
private void ShareScreenshotOnWhatsApp (){// Create composerWhatsAppShareComposer _composer = new WhatsAppShareComposer();_composer.AttachScreenShot();​// Show share viewNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
private void ShareImageOnWhatsApp (){// Create composerWhatsAppShareComposer _composer = new WhatsAppShareComposer();_composer.AttachImageAtPath(GetImageFullPath());​// Show share viewNPBinding.Sharing.ShowView(_composer, FinishedSharing);}
This allows sharing using all services. Optionally you can set ExcludedShareOptions attribute to exclude some services of your choice.
private void ShareTextMessageUsingShareSheet (){// Create share sheetShareSheet _shareSheet = new ShareSheet();_shareSheet.Text = m_shareMessage;​// Set this list if you want to exclude any service/application type. Else, ignore._shareSheet.ExcludedShareOptions = m_excludedOptions;​// Show composerNPBinding.UI.SetPopoverPointAtLastTouchPosition();NPBinding.Sharing.ShowView(_shareSheet, FinishedSharing);}
private void ShareURLUsingShareSheet (){// Create share sheetShareSheet _shareSheet = new ShareSheet();_shareSheet.Text = m_shareMessage;_shareSheet.URL = m_shareURL;​// Set this list if you want to exclude any service/application type. Else, ignore._shareSheet.ExcludedShareOptions = m_excludedOptions;​// Show composer at last touch pointNPBinding.UI.SetPopoverPointAtLastTouchPosition();NPBinding.Sharing.ShowView(_shareSheet, FinishedSharing);}
private void ShareScreenShotUsingShareSheet (){// Create share sheetShareSheet _shareSheet = new ShareSheet();_shareSheet.Text = m_shareMessage;​// Set this list if you want to exclude any service/application type. Else, ignore._shareSheet.ExcludedShareOptions = m_excludedOptions;​// Attaching screenshot here_shareSheet.AttachScreenShot();​// Show composerNPBinding.UI.SetPopoverPointAtLastTouchPosition();NPBinding.Sharing.ShowView(_shareSheet, FinishedSharing);}
private void ShareImageAtPathUsingShareSheet (){// Create share sheetShareSheet _shareSheet = new ShareSheet();_shareSheet.Text = m_shareMessage;_shareSheet.AttachImageAtPath(GetImageFullPath());​// Show composerNPBinding.UI.SetPopoverPointAtLastTouchPosition();NPBinding.Sharing.ShowView(_shareSheet, FinishedSharing);}