index.uts 691 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
// 引用 iOS 原生平台 api
import { UIDevice } from "UIKit";
import { Int } from 'Swift';

import { GetBatteryInfo, GetBatteryInfoSuccess } from '../interface.uts';

/**
 * 导出 获取电量方法 
 */
export const getBatteryInfo : GetBatteryInfo = function (options) {

    // 开启电量检测
    UIDevice.current.isBatteryMonitoringEnabled = true

    // 返回数据
    const res : GetBatteryInfoSuccess = {
        errMsg: "getBatteryInfo:ok",
        level: new Int(UIDevice.current.batteryLevel * 100),
        isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
    };
    options.success?.(res);
    options.complete?.(res);
23
}