快速检查Mac电池百分比 [英] Check Mac battery percentage in swift

查看:145
本文介绍了快速检查Mac电池百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试以编程方式检查mac电池电量.它可以在ios上完成,但是我想在mac.我发现它在stackoverflow上有一些资源,但是那些链接已被弃用.有任何想法吗?

I have been trying to check the mac battery level programmatically.it can be done on ios but i want to do it in mac.i found some resources on stackoverflow but those links were deprecated. Any Ideas?

推荐答案

首先创建一个"Umbrella-Bridging-Header.h" 内容:

First create a "Umbrella-Bridging-Header.h" with the content:

#import <IOKit/ps/IOPowerSources.h>

然后在main.swift中

then in main.swift

import Foundation

println("Hello, World!")
let timeRemaining = IOPSGetTimeRemainingEstimate ()
println("timeRemaining: \(timeRemaining)")

这篇关于快速检查Mac电池百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆