Javascript API Documentation

It is a javascript API that allows you to control the web view and the push-only prototype app provided by Swing2App.

In short, include and use the following js file through the API specification below and perform the functions you need.

Common js file Please include the following js file in your HTML file

<script src="https://pcdn2.swing2app.co.kr/swing_public_src/v3/2024_02_28_002/js/swing_app_on_web.js"></script>

WebView Javascript API Specifications

Webview Backwards

To Move to the previous page in the webview app. Same style as the back function in the web browser

swingWebViewPlugin.app.webview.back();

Webview Forward

Move to the front page in the webview app. Same style as the forward function in the web browser

swingWebViewPlugin.app.webview.forward();

• Go to Webview Home

Ability to navigate from the webview app to the home page (set initial page) set in the Swing2App.

swingWebViewPlugin.app.navigateToHome()

Clean Web Cache

Command to Clear Cache in WebView

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.webview.clearCache()

Controlling the Toolbar methods

• Enabling the Toolbar

You can control the Toolbar via API in a push-only prototype.

You can hide, enable, and set the auto-hide option for the toolbar while the app is running.

*Available from js lib version 2024_02_28_002

// toolbar active , autohide inactive
// swingWebViewPlugin.app.webview.updateToolbar(true,false)
// toolbar active , autohide active 
// swingWebViewPlugin.app.webview.updateToolbar(true,true)
// toolbar inactive , autohide inactive
// swingWebViewPlugin.app.webview.updateToolbar(false,false)
swingWebViewPlugin.app.webview.updateToolbar(false,false)

Get platform information

Functions for getting platform information from the web

if( swingWebViewPlugin.app.methods.getCurrentPlatform() == 'android' )
{
    console.log('android');
}
else if( swingWebViewPlugin.app.methods.getCurrentPlatform() == 'ios' )
{
    console.log('ios');
}
else
{
    console.log('web browser');
}

Get version and device information

A function that gets the version of the app and the H/W and S/W information of the device

// android
swingWebViewPlugin.app.methods.getAppVersion(function(value){
    console.log('model : ' + value.model);
    console.log('sdk_version : ' + value.version);
    console.log('version_release : ' + value.version_release);
    console.log('manufacturer : ' + value.manufacturer);
    console.log('app_version : ' + value.appVersion);
    console.log('radio_version : ' + value.radio_version);
    console.log('package_name : ' + value.packageName);
});

// ios
swingWebViewPlugin.app.methods.getAppVersion(function(value){
    console.log('model : ' + value.model);
    console.log('name : ' + value.name);
    console.log('systemVersion : ' + value.systemVersion);
    console.log('appVersion : ' + value.appVersion);
    console.log('bundleVersion : ' + value.bundleVersion);
    console.log('bundleID : ' + value.bundleID);
});

Close application

Command to terminate a running app

swingWebViewPlugin.app.methods.doExitApp();

Run a URL with an external browser

If you want to open a specific page with the default browser of an app such as Chrome or Safari, you can use the following function.

swingWebViewPlugin.app.methods.doExternalOpen('https://www.swing2app.com');

Run URLs with the embedded browser

Run using Android and iOS's own built-in browser.

If you must use Chrome and Safari, you can operate Chrome and Safari from inside the app through the code below.

swingWebViewPlugin.app.methods.openBrowser('https://www.swing2app.com');

Share the current page

Run the code below for the current Web page-sharing feature

swingWebViewPlugin.app.methods.doShareCurrentPage();

Share a custom URL

If you want to share the specified URL, run the code as shown below.

swingWebViewPlugin.app.methods.doShareWithUrl('https://www.swing2app.com');

Checking the notification setting status of the application

Ability to check the status of push alarm settings in the application.

If the push is disabled or if the push is turned off by the OS itself,

You can check if the app is turned off with its own settings.

swingWebViewPlugin.app.methods.isNotificationEnabled(function (result) {
    if( result == '1' ) // Able to send push notification
    {
        console.log('push active');
    }
    else if( result == 'off_on_system' )    // Disabling app push by OS setting
    {
        console.log('push inactive');
    }
    else if( result == 'off_on_app' )       // Disable App Push by App Settings
    {
        console.log('push inactive');
    }
});

Ex:) Code example for recommending activation when Off setting according to push setting

swingWebViewPlugin.app.methods.isNotificationEnabled(function (result) {
    if( result == '1' ) // Able to send push notification
    {
        console.log('push active');
    }
    else if( result == 'off_on_system' )    // Disabling app push by OS setting
    {
        console.log('push inactive');
        swingWebViewPlugin.app.methods.goToNotificationSetting("system"); // Open Notification Setting in System setting
    }
    else if( result == 'off_on_app' )       // Disable App Push by App Settings
    {
        console.log('push inactive');
        swingWebViewPlugin.app.methods.goToNotificationSetting("app");    // Open Notification Setting in App
    }
});

Ability to move alarm settings of applications or systems

(1) Go to the screen where you can set the alarm by the application itself

swingWebViewPlugin.app.methods.goToNotificationSetting('app');

(2) Go to the screen where you can set your own alarm for the system (Android, iOS)

swingWebViewPlugin.app.methods.goToNotificationSetting('system');

• Saving Text to Clipboard

A feature that allows you to save text to the clipboard.

Due to security issues, the window.navigator.clipboard.writeText API does not function properly in WebView.

In Swing2App WebView, you can use the following API to save text to the clipboard.

swingWebViewPlugin.app.methods.copyToClipboard("copyToClipboard Text test");

• Activate Push Notification

API to active push notification

swingWebViewPlugin.app.methods.activePush();

• Inactivate Push Notification

API to inactive push notification

swingWebViewPlugin.app.methods.inactivePush();

• Saving Variables on the Device

Saving Storage Variables within the App

If you have data you want to store in the app's storage, you can use the following function to save it.

You can utilize this feature to easily implement automatic website login.

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.methods.setVariable('id','test');

• Retrieving Saved Variables on the Device

Fetching Stored Variable Values within the App

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.methods.getVariable('id',function(value) {
    console.log(JSON.parse(value).value);
    // 출력예시 : test
});

• Playing TTS (Premium Feature) - Customization Required

Function to enable the TTS feature that converts text to speech

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.methods.speakOutViaTTS('hello');

• Checking First App Launch

API to check if the app is being launched for the first time, a function to determine the first launch of the app

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.methods.isFirstRun(function (value) {
    if (JSON.parse(value).result) 
    {
        console.log('First App Launching');
    }
});

Methods for Controlling App UI

• Setting Background Color for iOS

An option to set the SafeArea region and main color due to the device notch and home bar UI on iOS.

Please input the color as a hex value without the # symbol.

This setting only works on iOS.

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.ui.setIosBackColor('00ff00');

Method for Controlling App Screen

• Navigating to Settings Screen

API command to navigate to the settings screen.

You can move to the settings screen without using the toolbar or menu bar.

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.screen.setting.show();

• Navigating to Notification List Screen

API command to navigate to the notification list screen.

You can move to the notification list screen without using the toolbar or menu bar.

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.screen.notificationList.show();

• Navigating to Menu Screen

API command to navigate to the menu screen.

You can move to the menu screen without using the toolbar.

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.screen.menu.show();

• Navigating to Bookmark List Screen

API command to navigate to the bookmark list screen.

You can move to the bookmark list screen without using the menu or toolbar.

*Available from js lib version 2024_02_28_002

swingWebViewPlugin.app.screen.bookmarkList.show();

Application Event

Commands to manage the app's native events.

• Adding WebView Navigation Event for Android App Back Key

When you add an exit event to the app's Back button, the back navigation function triggered by the Back button will not work.

Therefore, if you add a backEvent, you need to implement the back navigation function yourself, as it will not work when the WebView navigation goes back due to the Back key.

swingWebViewPlugin.event.addEvent('backEvent' , function() {
    // Android back event 
    swingWebViewPlugin.app.webview.back(); // webview back navigation code
})

• Adding Exit Event for Android App Back Key

When you add an exit event to the app's back button, the app will not exit when the back button is pressed.

Therefore, if you add a backExitEvent, you need to implement the exit functionality directly within the callback function.

swingWebViewPlugin.event.addEvent('backExitEvent' , function() {
    // Implementing App Exit Logic Directly
    swingWebViewPlugin.app.methods.doExitApp();    // Exit App 
});

This is a command that allows you to manage in-app AdMob ads directly from the website.

Please refer to the information below to use the ads.

This command only works for apps with ad mob enabled

Show banner ads

Commands to display AdMob banner ads in applications

ParameterExplanationExample values

adId

Enter banner ad unit ID

ca-app-pub-3940256099942544/6300978111

swingWebViewPlugin.app.admob.showBanner('ca-app-pub-3940256099942544/6300978111');
  • End banner ads

Command to stop AdMob banner ads in the application

swingWebViewPlugin.app.admob.closeBanner();
  • Show interstitial ads

Commands to display AdMob interstitial ads in applications

ParameterExplanationExample values

adId

Enter interstitial unit ID

ca-app-pub-3940256099942544/6300978111

swingWebViewPlugin.app.admob.showInterstitialAd('ca-app-pub-3940256099942544/6300978111');

Last updated