How can I obtain the temperature of the Battery in IOS programatically. Also are there any API's in IOS that would give us any information on the Battery Manufacturer etc. Currently I am able to obtain the Battery level and charging status . Wanted to check if there is any other Battery related information that we can obtain in IOS
问题:
回答1:
That is not possible in the public API.
回答2:
As @Fogh correctly indicated, that isn't possible using the public API. The data is available in IOKit
, but IOKit
is considered a private framework on iOS. If you're developing for in-house distribution, just use IOKit
(here's an example program that shows how to get the data: https://github.com/eldoogy/EEIOKitListener)
If you're more adventurous and would like to somehow get this data in an App Store app, you can use a class I wrote called UIDeviceListener
that basically steals the data from the system without relying on any private APIs, but I cannot promise you that Apple will approve it... https://github.com/eldoogy/UIDeviceListener
Regardless of which approach you use, you will end up with a dictionary that contains a key called Temperature
, which is an integer representing battery temperature in Celsius (divide by 100 into a float
to get an accurate value).
回答3:
The manufacturer information could be hosted on your server and you just detect the device running your app, fetch the battery stats, parse and display.
For the battery temperature, if there are no APIs for it I guess that its an approximation using the current CPU usage and GPU usage or something?