// 引用 iOS 原生平台 api import { UIDevice } from "UIKit"; import { Int } from 'Swift'; /** * 定义 接口参数 */ export type GetBatteryInfoOptions = { success?: (res: object) => void; fail?: (res: object) => void; complete?: (res: object) => void; }; /** * 导出 获取电量方法 */ export function getBatteryInfo(options: GetBatteryInfoOptions) { // 开启电量检测 UIDevice.current.isBatteryMonitoringEnabled = true // 返回数据 const res = { errMsg: "getBatteryInfo:ok", level: new Int(UIDevice.current.batteryLevel * 100), isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging, }; options.success?.(res); options.complete?.(res); }