Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 951349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:43:18+00:00 2026-05-15T23:43:18+00:00

I have a simple question. How do I get iPhone’s battery level? [UIDevice currentDevice]

  • 0

I have a simple question. How do I get iPhone’s battery level?

[UIDevice currentDevice] batteryLevel]

Simple enough? However there is a little catch – I can’t use UIKit. Here is what I wrote so far, but I don’t think it works:

    // notification port
IONotificationPortRef nport = IONotificationPortCreate(kIOMasterPortDefault);

CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(nport), kCFRunLoopDefaultMode);

CFMutableDictionaryRef matching = IOServiceMatching("IOPMPowerSource");

kern_return_t kr = IOServiceAddMatchingNotification(nport, kIOFirstMatchNotification, matching, (IOServiceMatchingCallback)power, self, &powerIterator);

NSLog(@"Kernel said %d",kr);

power((void*)nport,powerIterator);

I’m still pretty sure you have to rely on IOKit in order to retrieve battery level. My application does not use UIKit as it is a low-level application in which UIKit cannot be used. Here are the frameworks I am using :

alt text http://img837.imageshack.us/img837/1829/screenshot20100718at211.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:43:19+00:00Added an answer on May 15, 2026 at 11:43 pm

    A while ago I wrote a program called iox that is similar to ioreg, except it makes it easier for me to translate back to IOKit calls. When I run that on my laptop, I see the following with a battery level.

    AppleSmartBattery - IOService:/AppleACPIPlatformExpert/SMB0/AppleECSMBusController/AppleSmartBatteryManager/AppleSmartBattery
            CurrentCapacity = 11678
            FullyCharged = YES
            DesignCapacity = 13000
            MaxCapacity = 11910
            ...
    

    In code, that is

    IOServiceNameMatching( "AppleSmartBattery" );
    

    I have no idea if the name would be the same on iOS, but I would try either finding a program like ioreg that you can run on the iPhone, or writing something simple to log the equivalent.

    ioreg is part of IOKitTools and it should just compile on iPhone.

    Edit:

    CFMutableDictionaryRef matching , properties = NULL;
    io_registry_entry_t entry = 0;
    matching = IOServiceMatching( "IOPMPowerSource" );
    //matching = IOServiceNameMatching( "AppleSmartBattery" );
    entry = IOServiceGetMatchingService( kIOMasterPortDefault , matching );
    IORegistryEntryCreateCFProperties( entry , &properties , NULL , 0 );
    NSLog( @"%@" , properties );
    CFRelease( properties );
    IOObjectRelease( entry );
    

    Add some safety checks. Once you figure out the specific properties you want, you can get them directly instead of using IORegistryEntryCreateCFProperties to get them all at once.

    IOKit represents everything as a big tree. IOPMPowerSource may not directly have the attributes you want, in which case you would need to iterate through the children. Using something like ioreg can tell you what you are looking for before you start coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a simple question in the objectify documentation it says that Only get(),
I have a simple question. I'm trying to get a list of the indicators
I have a very simple question, How can I get the POST values from
I have what I think is a simple question but I can't get it
i have a simple question, there is a function with parameter emp_id that opens
I have a simple iPhone app with several sounds already playing. However, one in
I have a simple question. Is it possible to somehow get a log of
I have 2 simple questions about python: 1.How to get number of lines of
I am new to Repository concept and get some questions. I have created simple
I have simple question. User supplies URL to my PHP script where I fetch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.