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?
Xcode 11 • Swift 5.1 Then you can create a computed property to return the battery level: Battery level ranges from 0.0 (fully discharged) to 1.0 (100% charged). Before accessing this property, ensure that battery monitoring is enabled. If battery monitoring is not enabled, battery state is UIDevice.
Show the percentage of battery charge in the menu bar On your Mac, choose Apple menu > System Preferences, then click Dock & Menu Bar . Click Battery in the sidebar (you may have to scroll to see it), then select “Show Percentage.”
Check battery life & useOpen your phone's Settings app. Under "Battery," see how much charge you have left, and about how long it will last. For details, tap Battery.
Answer: A: You would like the Battery Widget on your iPhone to show the battery charge levels for your iPhone, you Mac and your iPad. That is NOT possible. Those are individual widgets on individual devices.
First create a "Umbrella-Bridging-Header.h" with the content:
#import <IOKit/ps/IOPowerSources.h>
then in main.swift
import Foundation
println("Hello, World!")
let timeRemaining = IOPSGetTimeRemainingEstimate ()
println("timeRemaining: \(timeRemaining)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With