开发者

iPhone: Battery functions?

开发者 https://www.devze.com 2022-12-19 10:17 出处:网络
Are there Battery related API:s available in iPhone SDK? I want to find th开发者_如何学JAVAe battery draining state and other things related to battery from my application.Here\'s the example project

Are there Battery related API:s available in iPhone SDK? I want to find th开发者_如何学JAVAe battery draining state and other things related to battery from my application.


Here's the example project from Apple's Dev Center showing how you can read battery status.


UIDevice has the following properties:

batteryLevel

The battery charge level for the device.

@property (nonatomic,readonly) float batteryLevel

Discussion

Battery level ranges from 0.0 (fully discharged) to 1.0 (100% charged). Before accessing this property, ensure that battery monitoring is enabled.

If battery monitoring is not enabled, battery state is UIDeviceBatteryStateUnknown and the value of this property is –1.0.

batteryMonitoringEnabled

A Boolean value indicating whether battery monitoring is enabled (YES) or not (NO).

@property (nonatomic,getter=isBatteryMonitoringEnabled) BOOL batteryMonitoringEnabled

Discussion

Enable battery monitoring only when your application needs to be notified of changes to the battery state. Otherwise, disable battery monitoring. The default value is NO.

batteryState

The battery state for the device.

@property (nonatomic,readonly) UIDeviceBatteryState batteryState

Discussion

The value for batteryState is one of the constants in “UIDeviceBatteryState.”

If battery monitoring is not enabled, the value of this property is UIDeviceBatteryStateUnknown.

0

精彩评论

暂无评论...
验证码 换一张
取 消