How to detect from an iPhone app whether iPhone battery is in charging or not?

In my iPhone app, there is a requirement to know whether the iphone is charging or not?

If it is charging then I want to display alert for the same.

So how can I detect whether the iphone is Charging or not?

What should I do?

Please Help and Suggest.

Thanks.

Answers


[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
    //Device is connected (charging or fully charged)
}

Edit: If you relly want to check if the device is charging (and not 100% full yet), use the UIDeviceBatteryStateCharging constant in the if statement. See the documentation for more information.


Need Your Help

Do I need to use database transactions with c# TableAdapters?

c# transactions tableadapter

I found this great article on Transactions with Table Adapters. However, this article doesn't explain why Transactions are needed or even desirable!

innerHTML causes IE6 to (permanantly) lock up

javascript html internet-explorer-6 innerhtml

On a site I am working on I load up a series of images which can be animated using some controls I implemented w/javascript. Everything works just fine in all browsers but IE6 which locks up and n...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.