1

how can I search for connected bluetooth/wireless devices e.g. a Magic Mouse? How can I get the % of the battery??

Please post me some code and explain it because I found somethings but I don't understand it really.

Thank you very much for your help.

Charles
  • 50,943
  • 13
  • 104
  • 142
cocos2dbeginner
  • 2,185
  • 1
  • 31
  • 58

1 Answers1

2

I believe this can be answered with the following:

How to get the battery life of mac os x macbooks programatically?

Battery status in OSX?

Getting iPhone's battery level

How to get the Battery Charge Level specifically in mWh (not percentage) for Mac (Cocoa or C)

http://developer.apple.com/library/mac/#documentation/DeviceDrivers/Reference/IOBluetoothUI/index.html#//apple_ref/doc/uid/TP30000813

Hope it helps. This has been asked a few times as you can see.

Update

I know it's not Obj-C native api's but if you can't figure out IOPowerSources you can do this and parse the results

ioreg -l | grep BatteryPercent

Community
  • 1
  • 1
Andrew T Finnell
  • 13,417
  • 3
  • 33
  • 49
  • 1
    The problem is now how can I get the status OF THE MOUSE. The 4. link helped me a little bit but how can i get the mouse? – cocos2dbeginner Jan 07 '11 at 16:39
  • @cocos2dbeginner I really think link 1 will provide what you need. I know it doesn't talk about it specifically but all the batter levels can be obtained through IOPowerSources. If I had a Mac I would write some code for you. There is also an alternative if you can live with spawning a process, I updated my answer with it. – Andrew T Finnell Jan 07 '11 at 16:58
  • Hi tried this:NSTask *server=[NSTask new];[server setLaunchPath:@"/bin/sh"]; [server setArguments:[NSArray arrayWithObject:@"ioreg -c BNBMouseDevice | grep BatteryPercent"]]; NSPipe *outputPipe = [NSPipe pipe]; [server setStandardInput:[NSPipe pipe]]; [server setStandardOutput:outputPipe]; [server launch]; [server waitUntilExit]; [server release]; NSData *outputData = [[outputPipe fileHandleForReading] readDataToEndOfFile]; NSString *outputString = [[[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding] autorelease]; but it says no such file or directory found. terminal works – cocos2dbeginner Jan 07 '11 at 17:40