全部產品
Search
文件中心

SuperApp:裝置環境探測

更新時間:Oct 29, 2024

本文介紹裝置環境探測類WVNativeDetector相關的JS API,供您建立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));
});