Base

更新时间:
复制 MD 格式

This topic describes the JavaScript APIs of WVBase. You can refer to this topic when you create HTML5 apps or MiniApps by using Cross-platform DevOps. You can use the JavaScript APIs of Base to obtain and compare WindVane SDK versions, copy and paste the text, configure the UI background color, and determine whether the specified app is installed and whether the current WindVane SDK version supports the input APIs.

WVBase.checkWindVaneSDK

Note

This API is available only in WindVane iOS.

Compares the specified version of the WindVane SDK with the current version of the WindVane SDK.

Input parameters

  • [string]v: the version that you want to compare with the current version of the WindVane SDK, such as '5.3.0'.

Callback parameters

Callback parameters are passed by using the callback method. If the versions are compared, the success callback is invoked. Otherwise, the failure callback is invoked.

  • [string]isHigher: specifies whether the specified version of the WindVane SDK is later than the current version of the WindVane SDK. This parameter has the following valid values:

    • '1': the specified version of the WindVane SDK is later than the current version of the WindVane SDK.

    • '0': the specified version of the WindVane SDK is the same as the current version of the WindVane SDK.

    • '-1': the specified version of the WindVane SDK is earlier than the current version of the WindVane SDK.

var params = {
        // The version that you want to compare with the current version of the WindVane SDK.
        v: '5.3.0'
};
window.WindVane.call('WVBase', 'checkWindVaneSDK', params, function(e) {
        alert('success: ' + JSON.stringify(e));
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});

WVBase.copyToClipboard

Copies the specified text to the clipboard.

Input parameters

  • [string]text: the text that you want to copy to the clipboard.

Callback parameters

No callback parameters exist. If the text is copied, the success callback is invoked. Otherwise, the failure callback is invoked.

var params = {
        text: "text to copy"
};
window.WindVane.call('WVBase', 'copyToClipboard', params, function(e) {
        alert('success' + JSON.stringify(e));
}, function(e) {
        alert('failure' + JSON.stringify(e));
});

WVBase.isInstall

Determines whether the specified app is installed.

Note

In iOS 9 or later, you can determine whether an app is installed based only on the scheme that is configured in LSApplicationQueriesSchemes of info.plist.

Input parameters

  • [string]ios: the app label that is used in iOS. In iOS, the schema of an app is used as the label, such as 'taobao://'.

  • [string]android: the app label that is used in Android. In Android, the package name of an app is used as the label, such as 'com.taobao.taobao'.

Callback parameters

No callback parameters exist. If the system determines that the specified app is installed, the success callback is invoked. Otherwise, the failure callback is invoked.

var params = {
        // The app label that is used in iOS.
        ios: 'taobao://',
        // The app label that is used in Android.
        android: 'com.taobao.taobao'
};
window.WindVane.call('WVBase', 'isInstall', params, function(e) {
        alert('success');
}, function(e) {
        alert('failure');
});

WVBase.isAppsInstalled

Determines whether the specified apps are installed.

Note

In iOS 9 or later, you can determine whether an app is installed based only on the scheme that is configured in LSApplicationQueriesSchemes of info.plist.

Input parameters

  • [object]appName: the apps that you want to install. The value of this parameter is an object. The value contains the following properties:

    • [string]ios: the app label that is used in iOS. In iOS, the schema of an app is used as the label, such as 'taobao://'.

    • [string]android: the app label that is used in Android. In Android, the package name of an app is used as the label, such as 'com.taobao.taobao'.

Callback parameters

Callback parameters are passed by using the callback method. If the system determines that the apps are installed, the success callback is invoked. Otherwise, the failure callback is invoked.

  • [boolean]appName: indicates whether the specified apps are installed.

var params = {
        taobao: {
                ios: 'taobao://',
                android: 'com.taobao.taobao'
        },
        tmall: {
                ios: 'tmall://',
                android: 'com.tmall.tmall'
        }
};
window.WindVane.call('WVBase', 'isAppsInstalled', params, function(e) {
        alert('success: ' + JSON.stringify(e));
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});

WVBase.isWindVaneSDK

Obtains the current version of the WindVane SDK. If you do not use this API, you can obtain the current version of the WindVane SDK from your User-Agent (UA).

Input parameters

No input parameters exist.

Callback parameters

Callback parameters are passed by using the callback method. If the current version of the WindVane SDK is obtained, the success callback is invoked. Otherwise, the failure callback is invoked.

  • [string]os: the platform type. Valid values: 'ios' and 'android'.

  • [string]version: the version of the WindVane SDK.

  • [string]env: the client environment. Valid values: 'release', 'pre', and 'daily'. This parameter is used in WindVane iOS 8.1.0 or later.

  • [string]container: the type of the container. Valid values: 'WVWebView', 'WVWKWebView', 'WVUCWebView', and 'Weex'. This parameter is used in WindVane iOS 8.1.0 or later.

window.WindVane.call('WVBase', 'isWindVaneSDK', {}, function(e) {
        alert('success: ' + JSON.stringify(e));
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});

WVBase.notify

Note

This API is available only in WindVane iOS.

Triggers the specified event in document.

Input parameters

  • [string]event: the name of the event that the WVBase.notify API is called to trigger.

  • [object]param: the parameters of the event that the WVBase.notify API is called to trigger.

Callback parameters

No callback parameters exist, and no success or failure callback is invoked.

Event listening

The event is specified by the event parameter and the parameters of the event are specified by the param parameter.

document.addEventListener('MyNotifyName', function(e) {
        alert(JSON.stringify(e.param));
}, false);

var params = {
        // The name of the event that the WVBase.notify API is called to trigger.
        event: 'MyNotifyName',
        // The parameters of the event that the WVBase.notify API is called to trigger.
        param: { MyEventParam: 'paramValue' }
};
window.WindVane.call('WVBase', 'notify', params);

WVBase.openBrowser

Note

This API is available only in WindVane iOS.

Opens a new Safari page by using a specified URL.

Input parameters

  • [string]url: the URL that is displayed in Safari.

Important

Use JSBridge only when you need to ensure that the URL is opened in Safari. In other cases, use the <a> hyperlink, configure location.href, or configure iframe to go to the desired page.

Callback parameters

No callback parameters exist. If a Safari page is opened by using the specified URL, the success callback is invoked. Otherwise, the failure callback is invoked.

var params = {
        // The URL that is displayed in Safari.
        url: 'http://www.baidu.com'
};
window.WindVane.call('WVBase', 'openBrowser', params, function(e) {
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});

WVBase.setBackgroundColor

Note

This API is available only in WindVane iOS.

Configures the background color of WebView.

Input parameters

  • [string]color: the hexadecimal color codes of the background color of WebView. The 0X or # prefix is supported.

  • [number]alpha: optional. The opacity of the WebView background color. Valid values: [0, 1].

Callback parameters

No callback parameters exist. If the opacity of the WebView background color is configured, the success callback is invoked. Otherwise, the failure callback is invoked.

var params = {
        color: 'FF0000',
        alpha: 0.3
};
window.WindVane.call('WVBase', 'setBackgroundColor', params, function(e) {
        alert('success: ' + JSON.stringify(e));
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});

WVBase.canIUse

Note

This API is available only in WindVane Android 1.0.3.4 or later, WindVane iOS 2.1.4 or later.

Determines whether the current WindVane SDK version supports the input APIs.

Input parameters

  • [string]api: the name of the API, such as WVBase and WVMotion.

  • [string]method: optional. The method of the API, such as isWindVaneSDK and copyToClipboard. If you do not specify the method, you can only determine whether the current WindVane SDK version supports the input APIs.

Callback parameters

  • [boolean]canUse: true indicates that the current WindVane SDK version supports the input APIs, and false indicates that the current WindVane SDK version does not support the input APIs.

var params = {
        api: 'WVMotion',
        method: 'vibrate'
};
window.WindVane.call('WVBase', 'canIUse', params, function(e) {
        alert('success: ' + JSON.stringify(e));
}, function(e) {
        alert('failure: ' + JSON.stringify(e));
});