Cross Platform Native Plugins
A true cross platform tool for Unity which provides unique and unified way to access native functionality on mobile platforms.
Public Member Functions | List of all members
Sharing Class Reference

Provides cross-platform interface to various sharing services such as posting content to social media sites, sending items via email or SMS, and more. More...

Public Member Functions

void ShowView (IShareView _shareView, SharingCompletion _onCompletion)
 Shows the native view for sharing specified contents. More...
 
delegate void SharingCompletion (eShareResult _result)
 Delegate that will be called after share action is complete. More...
 
virtual bool IsMailServiceAvailable ()
 Determines whether the current device is able to send email. More...
 
virtual bool IsMessagingServiceAvailable ()
 Determines whether the current device is able to send text messages. More...
 
virtual bool IsFBShareServiceAvailable ()
 Determines whether the current device is able to post contents on Facebook. More...
 
virtual bool IsTwitterShareServiceAvailable ()
 Determines whether the current device is able to post contents on Twitter. More...
 
virtual bool IsWhatsAppServiceAvailable ()
 Determines whether the current device is able to share contents on WhatsApp. More...
 

Detailed Description

Provides cross-platform interface to various sharing services such as posting content to social media sites, sending items via email or SMS, and more.

The following code example shows how to compose mail with screenshot as attachment.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void ShareViaEmail ()
{
if (NPBinding.Sharing.IsMailServiceAvailable())
{
// Create new instance and populate fields
MailShareComposer _composer = new MailShareComposer();
_composer.Subject = "Sample email";
// Adding screenshot as attachment
_composer.AttachScreenShot();
// Show composer
NPBinding.Sharing.ShowView(_composer, OnFinishedSharing);
}
else
{
// Device doesn't support sending emails
}
}
private void OnFinishedSharing (eShareResult _result)
{
// Insert your code
}
}

The following code example shows how to compose text message.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void ShareViaMessage ()
{
if (NPBinding.Sharing.IsMessagingServiceAvailable())
{
// Create new instance and populate fields
MessageShareComposer _composer = new MessageShareComposer();
_composer.Body = "This is a test message.";
// Show composer
NPBinding.Sharing.ShowView(_composer, OnFinishedSharing);
}
else
{
// Device doesn't support sending messages
}
}
private void OnFinishedSharing (eShareResult _result)
{
// Insert your code
}
}

The following code example shows how to compose a post with a URL.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void ShareViaFB ()
{
if (NPBinding.Sharing.IsFBShareServiceAvailable())
{
// Create new instance and populate fields
FBShareComposer _composer = new FBShareComposer();
_composer.URL = "www.voxelbusters.com";
// Show composer
NPBinding.Sharing.ShowView(_composer, FinishedSharing);
}
else
{
// Device doesn't support posting on FB
}
}
private void OnFinishedSharing (eShareResult _result)
{
// Insert your code
}
}

The following code example shows how to compose a tweet message.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void ShareViaTwitter ()
{
if (NPBinding.Sharing.IsTwitterShareServiceAvailable())
{
// Create new instance and populate fields
TwitterShareComposer _composer = new TwitterShareComposer();
_composer.Text = "This is a test message.";
// Show composer
NPBinding.Sharing.ShowView(_composer, FinishedSharing);
}
else
{
// Device doesn't support posting on Twitter
}
}
private void OnFinishedSharing (eShareResult _result)
{
// Insert your code
}
}

The following code example shows how to compose a text message for sharing on WhatsApp.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void ShareViaWhatsApp ()
{
if (NPBinding.Sharing.IsWhatsAppServiceAvailable())
{
// Create new instance and populate fields
WhatsAppShareComposer _composer = new WhatsAppShareComposer();
_composer.Text = "This is a test message.";
// Show composer
NPBinding.Sharing.ShowView(_composer, FinishedSharing);
}
else
{
// Device doesn't support sharing on WhatsApp
}
}
private void OnFinishedSharing (eShareResult _result)
{
// Insert your code
}
}

The following code example demonstrates how to use share sheet.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void ShareViaShareSheet ()
{
// Create new instance and populate fields
ShareSheet _shareSheet = new ShareSheet();
_shareSheet.Text = "This is a test message.";
// On iPad, popover view is used to show share sheet. So we need to set its position
NPBinding.UI.SetPopoverPointAtLastTouchPosition();
// Show composer
NPBinding.Sharing.ShowView(_shareSheet, FinishedSharing);
}
private void OnFinishedSharing (eShareResult _result)
{
// Insert your code
}
}

The following code example demonstrates how to use share sheet with social network services only.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
public void ShareViaShareSheet ()
{
// Create new instance and populate fields
SocialShareSheet _shareSheet = new SocialShareSheet();
_shareSheet.Text = "This is a test message.";
// On iPad, popover view is used to show share sheet. So we need to set its position
NPBinding.UI.SetPopoverPointAtLastTouchPosition();
// Show composer
NPBinding.Sharing.ShowView(_shareSheet, FinishedSharing);
}
private void OnFinishedSharing (eShareResult _result)
{
// Insert your code
}
}

Member Function Documentation

void ShowView ( IShareView  _shareView,
SharingCompletion  _onCompletion 
)

Shows the native view for sharing specified contents.

Parameters
_shareViewThe object represents the composer that you want to use for sharing items.
_onCompletionCallback that will be called after operation is completed.
delegate void SharingCompletion ( eShareResult  _result)

Delegate that will be called after share action is complete.

Parameters
_resultThe result of the user’s action. This value will always be eShareResult.CLOSED, as its not possible to find out the share action selected by Android user.
virtual bool IsMailServiceAvailable ( )
virtual

Determines whether the current device is able to send email.

Returns
true if the device can send email; otherwise, false.
virtual bool IsMessagingServiceAvailable ( )
virtual

Determines whether the current device is able to send text messages.

Returns
true if the device can send text messages; otherwise, false.
virtual bool IsFBShareServiceAvailable ( )
virtual

Determines whether the current device is able to post contents on Facebook.

Returns
true if the device can post on Facebook; otherwise, false.
virtual bool IsTwitterShareServiceAvailable ( )
virtual

Determines whether the current device is able to post contents on Twitter.

Returns
true if the device can post on Twitter; otherwise, false.
virtual bool IsWhatsAppServiceAvailable ( )
virtual

Determines whether the current device is able to share contents on WhatsApp.

Returns
true if the device can share on WhatsApp; otherwise, false.