Ready to Level-Up?

This just in! If your rusty iOS skills could use some refining, or if you're just starting out and you want to level-up fast, consider signing up for our upcoming iOS Screencasts

New from iOS Rocket Surgery Swift Video Tutorials: The rapidly evolving Apple-iOS ecosystem has just been thrown into tumult with the recent introduction of the Swift Programming Language. Are you ready to finally try iOS development? Are you needing to switch from Objective-C to Swift? Sign up today for our free video courses!
(By the dear folks at Swift Tutorial Videos, a sister company)

Wednesday, December 18, 2013

iOS Get Battery Level

So, you want to programatically find your battery level on your iOS device?

The battery indicator on your iOS device is a useful indicator of how much battery you have remaining, and while it can't tell you how much time you have left, determining that a battery is withing 20% of shutting down is a useful thing to know, especially if you want to switch your app to operating in a less-CPU-intensive way. In my case, I record audio, and politely inform the user that their battery limit is approaching interesting levels.

If you want to determine the current battery level on your iOS device, here's an example of how to do it:


  float batteryLevel = [UIDevice currentDevice].batteryLevel;

Best practices suggest switching to a less CPU intensive mode when you run up against battery limits, though few people implement such things, its always a good idea to at least warn the user to save progress at these times, especially if the app is a mission-critical component to their work.

If you like to drink soda, juice, or water... we do too! We have so much in common. You should give us a +1 so you don't lose us... and we'll see you again soon.




About Me

Easy NSDateFormatter Tool

Save yourself some time in formatting your NSDates to NSStrings, and use the Blind NSDate app, which you can download from iTunes. There's also a website where you can format your NSDates: http://www.blindnsdate.com

Popular Posts

Designed By Seo Blogger Templates