Obtain Battery temperature in IOS programatically

2019-07-16 03:23发布

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

3条回答
一夜七次
2楼-- · 2019-07-16 03:28

That is not possible in the public API.

查看更多
贼婆χ
3楼-- · 2019-07-16 03:30

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).

查看更多
ゆ 、 Hurt°
4楼-- · 2019-07-16 03:54

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?

查看更多
登录 后发表回答