This topic describes the JavaScript APIs of WVNativeDetector. You can refer to this topic when you create HTML5 apps or MiniApps. You can use the JavaScript APIs of WVNativeDetector to obtain the device information, such as the device model, CPU usage, and memory usage.
WVNativeDetector.isSimulator
Obtains the information about whether the device is simulated.
Input parameters
No input parameters exist.
Callback parameters
Callback parameters are passed by using the callback method. If the requested information is obtained, the success callback is invoked. Otherwise, the failure callback is invoked.
[
boolean]isSimulator:trueindicates that the device is simulated. Otherwise, the value isfalse.
window.WindVane.call('WVNativeDetector', 'isSimulator', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});
WVNativeDetector.getCurrentUsage
Obtains the current CPU and memory usage.
This API operation causes performance loss. Call this API only when necessary.
Input parameters
No input parameters exist.
Callback parameters
Callback parameters are passed by using the callback method. If the CPU usage and memory usage are obtained, the success callback is invoked. Otherwise, the failure callback is invoked.
[
number]cpuUsage: the current CPU usage.[
number]memoryUsage: the current memory usage. The value is calculated by using the following formula:usedMemory/totalMemory.[
number]usedMemory: the total amount of memory consumed by the device, including the memory consumption of the current app and other running apps. Unit: MB.[
number]totalMemory: the total memory size of the current device. Unit: MB.
window.WindVane.call('WVNativeDetector', 'getCurrentUsage', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});
WVNativeDetector.getDeviceYear
Obtains the release year of the device. You can learn about the device performance based on its release year. You can easily identify the model of an iOS device and determine whether its performance is adequate based on the release year.
For Android devices, you can consider any device released in 2012 or later to be adequate.
Input parameters
No input parameters exist.
Callback parameters
Callback parameters are passed by using the callback method. If the release year is obtained, the success callback is invoked. Otherwise, the failure callback is invoked.
[
number]deviceYear: the release year of the device, such as2012.
window.WindVane.call('WVNativeDetector', 'getDeviceYear', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});
WVNativeDetector.getModelInfo
Obtains the device information, such as the device model.
Input parameters
No input parameters exist.
Callback parameters
Callback parameters are passed by using the callback method. If the device information is obtained, the success callback is invoked. Otherwise, the failure callback is invoked.
[
string]brand: the device brand, such as"Apple"and"Google".[
string]model: the device model, such as"iPhone","iPod touch", and"Nexus 5".[
string]platform: the device platform, such as"iPhone5,2". This parameter is available only whenWindVane iOSis used.[
string]platformName: the platform name of the device, such as"iPhone 5 (CDMA)". This parameter is easier to understand compared with theplatform. This parameter is available only whenWindVane iOSis used.
window.WindVane.call('WVNativeDetector', 'getModelInfo', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});
WVNativeDetector.getSafeAreaInsets
This API is available only in WindVane iOS.
Obtains the safe area information of the current view. This API is only available for full screen pages in iOS 11 and iPhone X or later.
Input parameters
No input parameters exist.
Callback parameters
Callback parameters are passed by using the callback method. If the safe area information is obtained, the success callback is invoked. Otherwise, the failure callback is invoked.
[
Number]top: the top edge inset value of the safe area.[
Number]left: the left edge inset value of the safe area.[
Number]bottom: the bottom edge inset value of the safe area.[
Number]right: the right edge inset value of the safe area.[
Boolean]cssAvaliable: specifies whether Cascading Style Sheets (CSS) is available, that is, whether the operating system isiOS 11or later and whether Xcode is used to develop the app or the MiniApp. You can also useconstant(safe-area-inset-*)to check the CSS availability.
window.WindVane.call('WVNativeDetector', 'getSafeAreaInsets', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});