I am using the CFProperty "AppleRawCurrentCapacity" value from IOServiceGetMathcingService( kIOMainPortDefault, IOServiceMatching( "AppleSmartBattery" ) ) to obtain the mAh value of the MacBook's battery. Once when the app receives the NSWorkspace notification of display sleep, and once again when receiving the NSWorkspace notification of display wake.
I then calculate how much battery was expended during sleep by deducting the pre value from post value.
The results can wildly vary, from it using 16 mAh per hour, to gaining 10 mAh an hour (without being plugged in). Sometimes a 10 hour sleep doesn't use any mAh... Which is clearly wrong.
When my app detects the key kIOPMPSInvalidWakeSecondsKey is present, I set a timer for that period + 3 seconds and attempt to read the battery values again. Yet the results can still wildly vary.
I see on Intel Macs there is a kIOPMPSMaxErrKey (set to 9 on a 2019 16"), however I don't see this on M1, and don't know how it can help, if it does exist.
Can anyone give me any pointers as to what I am doing wrong, or in the direction of obtaining reliable mAh values?
I like mAh as it's more precise that the standard integer values of 0 - 100, but I don't have to stick with mAh, I'd just don't like reporting that a 16 hour sleep didn't use any battery, when I know it's not true.
Thanks
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Using IOHIDManagerCopyDevices to get a list of keyboards and mice attached to Mac, triggers the user facing "Input Monitoring" request.
Because I'm NOT monitoring the users input, the result of the user selection makes no difference to the result, but the privacy warning dialog makes my app look suspicious.
All it is doing is checking to make sure that the customer has a non-Bluetooth keyboard or mouse, before they click the button to disable Bluetooth.
Is there a way a safe way (no private API please) to enumerate HID devices without this warning, or should I file a feedback asking Apple to reconsider what triggers this dialog?
I'm converting some code that reads a file's ACLs and I'm having a hard time with acl_free crashing. There is clearly something that I am not understanding.
// --- Do we have access control lists?
let fileSecurity = properties.fileSecurity
var accessList: acl_t?
if CFFileSecurityCopyAccessControlList( fileSecurity, &accessList ) {
print( "We have access control lists" )
acl_free( &accessList )
}
The line acl_free( &accessList ) crashes with the following.
malloc: *** error for object 0x16d28ac40: pointer being freed was not allocated
In the debugger I can see that accessList points to an object.
"accessList = acl_t? 0x000000015b00ea00"
I notice that the crash report ptr ref is different to what Xcode is showing in the debugger.
Also worth noting, is CFFileSecurityCopyAccessControlList takes a "UnsafeMutablePointer<acl_t?>!"
While acl_free takes a "void *obj_p"
Can anyone please give me a ptr as to what I am doing wrong?
16" MacBook Pro M2 Pro with Ventura 13.5 running Xcode 15.0
SwiftUI on macOS does so many things in way that I really love it, but it feels like I've run into an area that no-one at Apple seems to care about.
Text Editing
In order to get a TextEditor that could use the built-in Spelling & Grammar checking (without enabling Autocorrect), I had to host a NSTextView, which was an interesting experience for someone with only a few months of SwiftUI experience.
The default menu items "TextEditingCommands()" don't reflect the fields settings. The menu items do change the settings, but consistently show all the options as being unsellected.
I'd like to know if there's a secret sauce I'm missing that would enable these menuitems to reflect the settings of the focused field, or if like the TextEditor, these items need to be recreated and replaced to work as expected.
I understand that saving and reloading the settings per field is up to the individual developer, but it would be great if there is an over writable template that could handle this by default.