UniWebViewSafeBrowsing

Summary

UniWebView Safe Browsing provides a way for browsing the web content in a more browser-like way, such as Safari on iOS and Chrome on Android.

This class wraps SFSafariViewController on iOS and "Custom Tabs" on Android. It shares cookies, auto-fill completion and other more data with the browser on device. Most of permissions are also built-in supported. You can use this class for some tasks that are limited for a normal web view, such as using Apple Pay or Progressive Web Apps (PWA).

You create a UniWebViewSafeBrowsing instance by calling the static UniWebViewSafeBrowsing.Create method with a destination URL. You cannot change this URL once the instance is created. To show the safe browsing, call Show on the instance. The web content will be displayed in full screen with a toolbar containing the loaded URL, as well as some basic controls like Go Back, Go Forward and Done.

Browsing web content in UniWebViewSafeBrowsing is only supported on iOS and Android. There is no such component in Unity Editor. Creating and showing a UniWebViewSafeBrowsing on Unity Editor will fall back to open the URL in external browser by using Unity's Application.OpenURL.

Properties Summary

Whether the safe browsing mode is supported in current runtime or not.

Events Summary

Raised when user dismisses safe browsing by tapping the Done button or Back button.

Methods Summary

Creates a new UniWebViewSafeBrowsing instance with a given URL.

Shows the safe browsing content above current screen.

Dismisses the safe browsing component.

Sets the color for toolbar background in the safe browsing component.

Sets the color for toolbar controls in the safe browsing component.

Properties

Whether the safe browsing mode is supported in current runtime or not.

If supported, the safe browsing mode will be used when Show is called on a UniWebViewSafeBrowsing instance. Otherwise, the system default browser will be used to open the page when Show is called.

This property always returns true on iOS runtime platform. On Android, it depends on whether there is an Intent can handle the safe browsing request. Usually this ability is provided by Chrome, but there are also other browser app might implement that. If there is no Intent can open the URL in safe browsing mode, or the handling app is set to disabled in Android system, this property returns false.

To use this API on Android when you set your Target SDK to Android 11 or later, you need to add the correct intent query explicitly in your AndroidManifest.xml, to follow the Package Visibility (https://developer.android.com/about/versions/11/privacy/package-visibility). Add queries as a subnode of the manifest tag:

Example

<manifest>
  // ...

  </application>

  <queries>
    <intent>
      <action android:name="android.support.customtabs.action.CustomTabsService" />
    </intent>
  </queries>
</manifest>

// To use it:
if (UniWebViewSafeBrowsing.IsSafeBrowsingSupported) {
    // Safe Browsing Mode is available on current device.
}

Events

Raised when user dismisses safe browsing by tapping the Done button or Back button.

The dismissed safe browsing instance will be invalid after this event being raised, and you should not use it for another browsing purpose. Instead, create a new one for a new browsing session.

NOTICE

This event will not happen in Unity Editor, because the whole UniWebViewSafeBrowsing will fall back to an external browser.

Parameters
  • UniWebViewSafeBrowsing browsing

    The UniWebViewSafeBrowsing object raised this event.

Example

safeBrowsing.OnSafeBrowsingFinished += (browsing) => { 
    Debug.Log("UniWebViewSafeBrowsing closed.");
};

Methods

Creates a new UniWebViewSafeBrowsing instance with a given URL.

Parameters
  • string url

    The URL to navigate to. The URL must use the http or https scheme.

Example

var safeBrowsing = UniWebViewSafeBrowsing.Create("https://uniwebview.com");

Shows the safe browsing content above current screen.

Example

var safeBrowsing = UniWebViewSafeBrowsing.Create("https://uniwebview.com");
safeBrowsing.Show();

Dismisses the safe browsing component.

This method only works on iOS. On Android, there is no way to dismiss the safe browsing component

Sets the color for toolbar background in the safe browsing component.

The changes are ignored after Show method is called.

Parameters
  • Color color

    The color to tint the toolbar.

Example

safeBrowsing.SetToolbarColor(Color.blue);

Sets the color for toolbar controls in the safe browsing component.

The changes are ignored after Show method is called.

This method only works on iOS. On Android, the controls color is determined by system to keep a reasonable contrast, based on the toolbar background color you provided in SetToolbarColor.

Parameters
  • Color color

    The color to tint the controls on toolbar.

Example

safeBrowsing.SetToolbarItemColor(Color.yellow);