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

Represents an immutable object, that holds information about a message sent from native webview. More...

Properties

string URL [get, protected set]
 The custom URL that holds information about the web view message. (read-only) More...
 
string Scheme [get, protected set]
 The scheme name of the web view message. (read-only) More...
 
string Host [get, protected set]
 The host name of the web view message. (read-only) More...
 
Dictionary< string, string > Arguments [get, protected set]
 The arguments of the web view message. (read-only) More...
 

Detailed Description

Represents an immutable object, that holds information about a message sent from native webview.

When a webpage with registered scheme starts loading, webview raises WebView.DidReceiveMessageEvent along with WebViewMessage object. Using WebViewMessage object, you can get additional information about URL such as host, scheme and arguments.

You can register your own scheme, by calling WebView.AddNewURLSchemeName before starting load request.

Please check following code sample, for easy understanding about scheme registeration and handling messages.

using System.Collections;
public class ExampleClass : MonoBehaviour
{
[SerializeField]
private WebView m_webview;
private string m_url = "unity://action?val1=1&val2=2";
private void Start ()
{
// Registering scheme of loading url
m_webview.AddNewURLSchemeName("unity");
}
private void OnEnable ()
{
// Registering for event
WebView.DidReceiveMessageEvent += OnDidReceiveMessage;
}
private void OnDisable ()
{
// Unregistering event
WebView.DidReceiveMessageEvent -= OnDidReceiveMessage;
}
public void LoadRequest ()
{
m_webview.LoadRequest(m_url);
}
private void OnDidReceiveMessage (WebView _webview, WebViewMessage _message)
{
if (_webview == this.m_webview)
{
Debug.Log("Scheme: " + _webview.SchemeName);
Debug.Log("Host: " + _webview.Host);
foreach (string _argKey in _message.Arguments.Keys)
Debug.Log("Arg key: " + _argKey + "value: " + _message.Arguments[_argKey]);
}
}
}

Output

Scheme: unity
Host: action
Arg key: val1 value: 1
Arg key: val2 value: 2

Property Documentation

string URL
getprotected set

The custom URL that holds information about the web view message. (read-only)

string Scheme
getprotected set

The scheme name of the web view message. (read-only)

string Host
getprotected set

The host name of the web view message. (read-only)

Dictionary<string, string> Arguments
getprotected set

The arguments of the web view message. (read-only)

Each key-value pair in dictionary represents argument name and its corresponding value.