Client

A client opens the Game Client from a URL Received by Game-ox.com

The Client App should pass the following parameters to the Game Client URL.

Parameters:

Param
Val
Required
Description

token

String

YES

The User API Authoriaztion Token

lang

String

NO

The Game Lang Default: ar

Example:

https://1231example.cloudfront.net/game/index.html
?token=xxxxx&lang=en

Once you passed a valid parameters you should see the game started.

Android API

The webview may need to interact with the application for example the webview may send you message in order a player how need to re-charge or it needs the web-view background to be transparent or close the webview

webView.addJavascriptInterface(WebAppInterface(view.context), "Android")
inner class WebAppInterface(private val mContext: Context) {
    @JavascriptInterface
    /** 
     The following methods is called by the Web-View
    */
    fun closeWindow() {
        // close webview
        // dismiss()
    }
    @JavascriptInterface
    fun openChargePage() {
        // start charge page activity
    }
    @JavascriptInterface
    fun backgroundTransparent() {
        // set webview background transparent
    }
    
     @JavascriptInterface
    fun orientationLandscape() {
        // set webview background transparent
    }
}

IOS API

1- import WebKit
2- Implement WKUIDelegate ,WKScriptMessageHandler
3- Connect with UI
@IBOutlet weak var webViewContainer: UIView!
4- Define variables

var webView: WKWebView!
var transparentWebView = false


5- First Method : 
override func viewWillAppear(_ animated: Bool) {
        if transparentWebView == true {
            self.webViewTransparent()
        }
    }


6- Handle Transparent case 
func webViewTransparent() {
        webView.backgroundColor = .clear
        webView.isOpaque = false
        view.backgroundColor = .clear
    }


7- Then you can make configuration for webView 
    fileprivate func setupUI() {
        self.title = ""
        let contentController = WKUserContentController()
        contentController.add(
            self,
            name: "Mobile"
        )
        let config = WKWebViewConfiguration()
        config.userContentController = contentController
        webView = WKWebView(frame: webViewContainer.bounds, configuration: config)
        webView.translatesAutoresizingMaskIntoConstraints = false
        webViewContainer.addSubview(webView)
        webV1- import WebKit


2- Implement WKUIDelegate ,WKScriptMessageHandler


3- Connect with UI
@IBOutlet weak var webViewContainer: UIView!


4- Define variables
var webView: WKWebView!
var transparentWebView = false


5- First Method : 
override func viewWillAppear(_ animated: Bool) {
        if transparentWebView == true {
            self.webViewTransparent()
        }
    }


6- Handle Transparent case 
func webViewTransparent() {
        webView.backgroundColor = .clear
        webView.isOpaque = false
        view.backgroundColor = .clear
    }


7- Then you can make configuration for webView 
    fileprivate func setupUI() {
        self.title = ""
        let contentController = WKUserContentController()
        contentController.add(
            self,
            name: "Mobile"
        )
        let config = WKWebViewConfiguration()
        config.userContentController = contentController
        webView = WKWebView(frame: webViewContainer.bounds, configuration: config)
        webView.translatesAutoresizingMaskIntoConstraints = false
        webViewContainer.addSubview(webView)
        webView.leadingAnchor.constraint(equalTo: webViewContainer.leadingAnchor, constant: 0).isActive = true
        webView.trailingAnchor.constraint(equalTo: webViewContainer.trailingAnchor, constant: 0).isActive = true
        webView.topAnchor.constraint(equalTo: webViewContainer.topAnchor, constant: 0).isActive = true
        webView.bottomAnchor.constraint(equalTo: webViewContainer.bottomAnchor, constant: 0).isActive = true
        webView.navigationDelegate = self
        webView.uiDelegate = self
     
        if let urlPath = URL(string: url) {
            webView.load(URLRequest(url: urlPath))
        }
    }


8- You can call this message to handle response 
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        getMessageData(message: message)
    }


9- Then handle getMessage method 
func getMessageData(message: WKScriptMessage) {
        guard let data = message.body as? NSDictionary else {return}
if let methodName = data["method_name"] as? String {
switch methodName {
case "closeWindow":
                navigationController?.popViewController(animated: true)
                dismiss(animated: true, completion: nil)
case "openChargePage":
                let view = WalletRouter.createModule()
                navigationController?.pushViewController(view, animated: true)
case "backgroundTransparent":
                hideNavigationBar()
                webViewTransparent()
}
}
}iew.leadingAnchor.constraint(equalTo: webViewContainer.leadingAnchor, constant: 0).isActive = true
        webView.trailingAnchor.constraint(equalTo: webViewContainer.trailingAnchor, constant: 0).isActive = true
        webView.topAnchor.constraint(equalTo: webViewContainer.topAnchor, constant: 0).isActive = true
        webView.bottomAnchor.constraint(equalTo: webViewContainer.bottomAnchor, constant: 0).isActive = true
        webView.navigationDelegate = self
        webView.uiDelegate = self
     
        if let urlPath = URL(string: url) {
            webView.load(URLRequest(url: urlPath))
        }
    }


8- You can call this message to handle response 
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        getMessageData(message: message)
    }


9- Then handle getMessage method 
func getMessageData(message: WKScriptMessage) {
        guard let data = message.body as? NSDictionary else {return}
if let methodName = data["method_name"] as? String {
switch methodName {
case "closeWindow":
                navigationController?.popViewController(animated: true)
                dismiss(animated: true, completion: nil)
case "openChargePage":
                let view = WalletRouter.createModule()
                navigationController?.pushViewController(view, animated: true)
case "backgroundTransparent":
                hideNavigationBar()
                webViewTransparent()
}
}
}

Last updated