Link up
This guide covers a hypothetical scenario where you have a hybrid app running on Android and iOS. It explains how to bridge the gap between HTML views and native views so that you can log events in your HTML views and send them to your app.
To apply this method, SDK installation and integration must be done first.
JavaScript interface
Both Android and iOS have native JavaScript interfaces that allow you to call native code from web views.
Android: JavascriptInterface
iOS: JavaScriptCore
Implementation consists of the following steps:
HTML code for Webview or webpage
Native code implementation for Webview
Android
HTML code for Android
Add the following HTML code to your Webview or web page.
<h1>Logging Event From Web View</h1>
<div id="main">
<button id="logSignUpEvent" onclick="logSignUPEvent()"> SignUp </button>
</div>
<script type="text/javascript">
function logLoginEvent(){
var eventName = "df_sign_up"
var eventProperty = {'df_sign_channel': 'Facebook'};
window.customJsBridge.logEvent(eventName, JSON.stringify(eventProperty));
}
</script>WebActivity class
Create a web activity class using the following code.
Javascript interface class
Create a MainJsInterface class that will implement invoke() with JavascriptInterface.
iOS
HTML code for iOS
Add the following HTML code to your Webview or web page.
WKWebView Settings
Please connect the messageHandler of the WKWebView object as follows and load the webview.
Learn more
Enter date and time format properties
Date and time formats yyyy-MM-dd'T'HH:mm:ss.SSS'Z'must be entered as strings in the format.
Set user identification information
DFINERY Android SDK accepts user identification information as an Enum. To enter user identification information in HTML, it is recommended to input the value of the user identification information constant, convert the string to an Enum in the JavaScript interface, and then call it.
Javascript
Last updated