import { UTSiOS } from "DCloudUTSFoundation"; import { DeviceUtil } from './device/DeviceUtil.uts'; import { GetDeviceInfo, GetDeviceInfoOptions, GetDeviceInfoResult } from '../interface.uts' export const getDeviceInfo : GetDeviceInfo = (config : GetDeviceInfoOptions | null) : GetDeviceInfoResult => { let filter : Array = []; if (config != null && config?.filter != null) { let temp = config?.filter; filter = temp!; } if (config == null || filter.length == 0) { const defaultFilter = [ "brand", "deviceBrand", "deviceId", "model", "deviceModel", "deviceType", "deviceOrientation", "devicePixelRatio", "system", "platform", "isRoot", "isSimulator" ]; filter = defaultFilter; } return getBaseInfo(filter); } function getBaseInfo(filterArray : Array) : GetDeviceInfoResult { const osVersion = DeviceUtil.getOSVersion(); let result : GetDeviceInfoResult = {}; if (filterArray.indexOf("brand") != -1) { result.brand = "apple"; } if (filterArray.indexOf("deviceBrand") != -1) { result.deviceBrand = "apple"; } if (filterArray.indexOf("deviceId") != -1) { result.deviceId = UTSiOS.getDeviceId(); } if (filterArray.indexOf("model") != -1) { result.model = UTSiOS.getModel(); } if (filterArray.indexOf("deviceModel") != -1) { result.deviceModel = UTSiOS.getModel(); } if (filterArray.indexOf("deviceType") != -1) { result.deviceType = DeviceUtil.isPad() ? "pad" : "phone"; } if (filterArray.indexOf("deviceOrientation") != -1) { result.deviceOrientation = DeviceUtil.getOrientation(); } if (filterArray.indexOf("devicePixelRatio") != -1) { result.devicePixelRatio = DeviceUtil.getScreenScale(); } if (filterArray.indexOf("system") != -1) { result.system = String(format = "iOS %@", osVersion); } if (filterArray.indexOf("platform") != -1) { result.platform = "ios"; } if (filterArray.indexOf("isRoot") != -1) { result.isRoot = DeviceUtil.hasRootPrivilege(); } if (filterArray.indexOf("isSimulator") != -1) { result.isSimulator = UTSiOS.isSimulator(); } return result; }