Obtain Battery temperature in IOS programatically

余生长醉 提交于 2020-01-04 15:27:35

问题


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?



来源:https://stackoverflow.com/questions/16287831/obtain-battery-temperature-in-ios-programatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!