Device environment detection

更新时间:
复制 MD 格式

This topic describes the JavaScript (JS) APIs for the WVNativeDetector class, which is used to detect the device environment. You can use these APIs when you create H5 applications or miniapps for cross-platform development. These APIs allow you to retrieve device information, such as the device model, CPU, and memory usage.

WVNativeDetector.isSimulator

Checks whether the current environment is an emulator.

Input parameters

No input parameters are required.

Callback parameters

The parameters are passed to the callback method. The success callback is invoked if the emulator information is retrieved. Otherwise, the failure callback is invoked.

  • [boolean] isSimulator: A value of true indicates that the current environment is an emulator. Otherwise, the value is false.

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

WVNativeDetector.getCurrentUsage

Retrieves the current CPU and memory usage information.

Note

Calling this API can degrade performance. Call it only when necessary.

Input parameters

None.

Callback parameters

The parameters are passed to the callback method. The success callback is invoked if the usage information is retrieved. Otherwise, the failure callback is invoked.

  • [number] cpuUsage: The current CPU usage.

  • [number] memoryUsage: The current memory usage. This value is calculated as usedMemory / totalMemory.

  • [number] usedMemory: The amount of memory that is currently used by the device, in MB. This includes the memory used by the current application and other running applications.

  • [number] totalMemory: The total memory of the device, in MB.

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

WVNativeDetector.getDeviceYear

Retrieves the release year of the device. This information can be used to estimate device performance. The release year is generally accurate for iOS devices. For Android devices, this information helps provide a performance estimate.

Devices released in or after 2012 are generally considered to have sufficient performance for most needs.

Input parameters

This operation takes no input parameters.

Callback parameters

The parameters are passed to the callback method. The success callback is invoked if the device release year is retrieved. Otherwise, the failure callback is invoked.

  • [number] deviceYear: The release year of the device, such as 2012.

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

WVNativeDetector.getModelInfo

Retrieves device information, such as the device model.

Input parameters

There are no input parameters.

Callback parameters

The parameters are passed to the callback method. The success callback is invoked if the device information is retrieved. Otherwise, the failure callback is invoked.

  • [string] brand: The device brand, such as "Apple" or "Google".

  • [string] model: The device model, such as "iPhone", "iPod touch", or "Nexus 5".

  • [string] platform: The device platform, such as "iPhone5,2". This parameter applies only to VER.WindVane iOS.

  • [string] platformName: The human-readable device platform name, such as "iPhone 5 (CDMA)". This parameter is more readable than platform and applies only to VER.WindVane iOS.

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

WVNativeDetector.getSafeAreaInsets

Note

This API applies only to WindVane iOS.

Retrieves the safe area insets for the current page. This API applies only to full-screen pages and is used to ensure page compatibility with iOS 11 and iPhone X.

Input parameters

This operation has no input parameters.

Callback parameters

The parameters are passed to the callback method. The success callback is invoked if the safe area information is retrieved. Otherwise, the failure callback is invoked.

  • [number] top: The top inset of the safe area.

  • [number] left: The left inset of the safe area.

  • [number] bottom: The bottom inset of the safe area.

  • [number] right: The right inset of the safe area.

  • [boolean] cssAvailable: Indicates whether the constant(safe-area-inset-*) CSS function is available. This is true if the system is VER.iOS 11 or later and the client was compiled with Xcode.

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