Documentation for Appmosts javascript bindings. Available for Appmost Hybrid+ apps
Functions
openBankId
getFirebasePushToken
getPushToken
clearWebViewCache
setInitialUrlOverride
showDialog
addUrlToOpenInternally
clearWebViewCacheWithReload
clearUrlListToOpenInternally
showFreshChat
downloadPdf
iOS vs Android
Native javascript bindings are called differently on iOS and on Android. Prefer to use a helper function which checks the user agent and calls the function the right way. See the example below. The example also demonstrates how to use callback functions and fetching push notifications with or without Firebase.
<script type = "text/javascript">
/// Reusable function to call iOS and Android native bindings in an Appmost app
/// Example: callNativeFunction("showDialog", { title: "Title here", message: "Message here"});
function callNativeFunction(functionName, parameters) {
let functionObj = { function: functionName }
let methodCall = { ...functionObj, ...parameters };
const iOSUserAgents = ['ios', 'iphone', 'ipad'];
const userAgentIncludesIOS = iOSUserAgents.some((t) => navigator.userAgent.includes(t));
if (userAgentIncludesIOS) {
if (window.webkit?.messageHandlers?.appmostCallback) {
window.webkit.messageHandlers.appmostCallback.postMessage(methodCall);
}
} else if (navigator.userAgent.includes("android")) {
let json = JSON.stringify(methodCall);
appmostCallback.postMessage(json);
}
}
/// Only to be used when Firebase is used for Push Notifications
function getFirebaseToken() {
callNativeFunction("getFirebasePushToken", { callbackFunction: 'didRecieveFirebasePushToken' })
}
function getPushToken() {
callNativeFunction("getPushToken", { callbackFunction: 'didRecievePushToken' })
}
function didRecieveFirebasePushToken(token, error) {
if (token != null) {
alert ("Got token: " + token);
} else {
alert ("Got token error: " + error);
}
}
function didRecievePushToken(token, error) {
if (token != null) {
alert ("Got token: " + token);
} else {
alert ("Got token error: " + error);
}
}
</script>More examples
<script type = "text/javascript">
function clearWebViewCacheWithReload() {
callNativeFunction('clearWebViewCacheWithReload', {})
}
function showDialog() {
callNativeFunction("showDialog", { title: "Titel", message: "Testar"} )
}
function includeUrl() {
// Leading "https", "http" and "www" are ignored when comparing leading urls in Appmost
callNativeFunction("addUrlToOpenInternally", { url: "www.domain.here/optional_path", showDialog: "true"})
}
</script>