GUAWebViewResultObserver
Register the callback of the Player Network SDK WebView module, the game needs to process the callback function. For more information on the callback data structure, see GUAWebViewRet.
note
[Player Network SDK & MSDK] It is strongly recommended to perform registration in the startup function of the game application.
Function Definition
- Unity
- Unreal Engine
The list of methods used to process the callback events.
Callback Event | Common | [Player Network SDK Only] | [MSDK Only] |
---|---|---|---|
WebViewRetEvents | OpenUrl, CallJS, GetEncodeUrl | QueryDeviceLevel | OpenGameDataAuthCenter, OpenAmsCenter |
event OnResultHandler<GUAWebViewRet> WebViewRetEvents;
The list of methods used to process the callback events.
Callback Event | Common | [Player Network SDK Only] | [MSDK Only] |
---|---|---|---|
OnWebViewOptNotify | OpenUrl, CallJS, GetEncodeUrl | QueryDeviceLevel | OpenGameDataAuthCenter, OpenAmsCenter |
class GUA_EXTERN GUAWebViewObserver
{
public:
virtual ~GUAWebViewObserver() {};
virtual void OnWebViewOptNotify(const GUAWebViewRet &webview_ret) {};
};
Code Sample
- Unity
- Unreal Engine
// Add callbacks
UnionAdapterAPI.GetWebViewService().WebViewRetEvents += OnWebViewRetEvent;
// Remove callbacks
UnionAdapterAPI.GetWebViewService().WebViewRetEvents -= OnWebViewRetEvent;
// Process the WebViewRetEvents callback
private void OnWebViewRetEvent(GUAWebViewRet ret)
{
string methodTag = "";
if (ret.MethodId == (int)GUAMethodID.GUA_WEBVIEW_GET_ENCRYPT_URL) {
methodTag = "GetEncodeUrl";
}
else if (ret.MethodId == (int)GUAMethodID.GUA_WEBVIEW_JS_CALL)
{
methodTag = "JsCall";
UnionAdapterAPI.GetWebViewService().CallJS(WebViewSample.callJSParams);
}
else if (ret.MethodId == (int)GUAMethodID.GUA_WEBVIEW_JS_SHARE)
{
methodTag = "JsShare";
}
else if (ret.MethodId == (int)GUAMethodID.GUA_WEBVIEW_CLOSE_URL)
{
methodTag = "Close WebView";
}
else if (ret.MethodId == (int)GUAMethodID.GUA_WEBVIEW_JS_IS_APP_INSTALLED)
{
methodTag = "IsAppInstalled";
}
Debug.Log(methodTag + ret.ToString());
}
// 1. Define an observer class that inherits from GUA_NAMESPACE::GUAWebViewObserver at the engine level.
// 2. Implement a callback interface with the same method name such as OnWebViewOptNotify.
class FGUAWebViewObserver : public GUA_NAMESPACE::GUAWebViewObserver {
public:
static FGUAWebViewObserver Instance;
void OnWebViewOptNotify(const GUA_NAMESPACE::GUAWebViewRet &webview_ret)
{
}
};
FGUAWebViewObserver FGUAWebViewObserver::Instance;
//Configure the callback
GUA_NAMESPACE::GUAWebViewService::SetWebViewObserver(&FGUAWebViewObserver::Instance);