Usage
The Xamarin SDK largely follows the native implementations for Android and iOS. However, names of classes and interfaces are adapted to C# conventions. Also a few differences need to be considered.
Xamarin specific topics
Interface
The SDK is available by using the method of the interface IChatvisor
. An instance for the platform the code is running on (Android or iOS) can be obtained by calling Chatvisor.Instance
.
using Xamarin.LiveView;
using Xamarin.LiveView.Abstractions;
...
IChatvisor instance = Chatvisor.Instance;
instance.Init("your-tenant-id", "your-token");
User tagging
For user tagging instances of the class ActiveUser
are used (see the Android documentation for an example). Because of restrictions of the Xamarin environment, the constructor cannot be called directly. As a solution Chatvisor.Instance.CreateUser()
can be used which yields a new empty instance of the ActiveUser
class (implementing the interface IActiveUser
) for the current platform.
IActiveUser user = instance.CreateUser()
.WithEmail("john.doe@example.org")
Chatvisor.Instance.User.Tag(user);
Example
namespace TestApp
{
public partial class MainPage : ContentPage
{
private IChatvisor instance;
public MainPage()
{
InitializeComponent();
instance = Chatvisor.Instance;
instance.Init("user", "...");
}
void CoBrowsingStartClicked(System.Object sender, System.EventArgs e)
{
instance.CoBrowsing.Start();
}
}
}