设备环境探测
本文介绍设备环境探测类WVNativeDetector相关的JS API,供您在通过跨平台DevOps创建H5端应用或者小程序时参考。设备环境探测类WVNativeDetector的JS API提供获取设备相关信息的能力,例如设备型号、CPU和内存使用率。
WVNativeDetector.isSimulator
获取当前环境是否是模拟器。
输入参数
无输入参数。
回调参数
回调参数将会在回调方法中传递,如果成功获取模拟器信息,则进入success
回调,否则进入failure
回调。
[
boolean
]isSimulator:如果当前环境是模拟器,则为true
,否则为false
。
window.WindVane.call('WVNativeDetector', 'isSimulator', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});
WVNativeDetector.getCurrentUsage
获取当前的CPU和内存使用率信息。
调用该接口会存在性能损耗,因此请仅在必要时调用。
输入参数
无输入参数。
回调参数
回调参数将会在回调方法中传递,如果成功获取使用率信息,则进入success
回调,否则进入failure
回调。
[
number
] cpuUsage:当前 CPU 使用率。[
number
] memoryUsage:当前内存使用率,值为usedMemory / totalMemory
。[
number
] usedMemory:当前手机的内存使用总量,包含当前应用和其它打开的应用的内存使用量,单位:MB。[
number
] totalMemory:当前手机的内存总量,单位:MB。
window.WindVane.call('WVNativeDetector', 'getCurrentUsage', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});
WVNativeDetector.getDeviceYear
获取设备的发布日期,可以用于估算设备的性能。iOS可以基本准确地获得设备的发布日期,估算Android设备性能。
一般认为2012年及以后发布的机器,其性能可以满足绝大多数需要。
输入参数
无输入参数。
回调参数
回调参数将会在回调方法中传递,如果成功获取设备的发布日期,则进入success
回调,否则进入failure
回调。
[
number
]deviceYear:设备的发布日期,如2012
。
window.WindVane.call('WVNativeDetector', 'getDeviceYear', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});
WVNativeDetector.getModelInfo
获取设备型号等信息。
输入参数
无输入参数。
回调参数
回调参数将会在回调方法中传递,如果成功获取设备信息,则进入 success
回调,否则进入 failure
回调。
[
string
] brand:设备品牌,例如"Apple"
或"Google"
。[
string
] model:设备型号,例如"iPhone"
或"iPod touch"
或"Nexus 5"
。[
string
] platform:设备平台,例如"iPhone5,2"
,仅限VER.WindVane iOS
。[
string
] platformName:设备平台,相比platform
更易读一些,例如"iPhone 5 (CDMA)"
,仅限VER.WindVane iOS
。
window.WindVane.call('WVNativeDetector', 'getModelInfo', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});
WVNativeDetector.getSafeAreaInsets
该API仅适用于WindVane iOS。
获取当前页面的安全区域信息,仅适用于全屏页面,用于页面对iOS11/iPhoneX 做兼容。
输入参数
无输入参数。
回调参数
回调参数将会在回调方法中传递,如果成功获取SafeArea信息,则进入success
回调,否则进入failure
回调。
[
Number
]top:SafeArea的顶部inset。[
Number
]left:SafeArea的左边inset。[
Number
]bottom:SafeArea的底部inset。[
Number
]right:SafeArea的右边inset。[
Boolean
]cssAvaliable:constant(safe-area-inset-*)
的CSS是否可用,等价于判断系统是否是VER.iOS 11
或更高,且客户端使用Xcode进行编译。
window.WindVane.call('WVNativeDetector', 'getSafeAreaInsets', {}, function(e) {
alert('success: ' + JSON.stringify(e));
}, function(e) {
alert('failure: ' + JSON.stringify(e));
});