您的位置:首页 > 运维架构

【Topics Power】Reduce Power Consumption

2014-09-22 14:21 246 查看
You can help improve batterylife by optimizing your use of the following features:

The CPU
Wi-Fi, Bluetooth, and baseband (EDGE, 3G) radios
The Core Location framework
The accelerometers
The disk 

The goal of your optimizations should be to do the most work you can in the most efficient way possible. Youshould always optimize your app’s algorithms using Instruments. But even the most optimized algorithm
canstill have a negative impact on a device’s battery life. You should therefore consider the following guidelineswhen writing your code:

Avoid doing work that requires polling. Polling prevents the CPU from going to sleep. Instead of polling,use the
NSRunLoop or
NSTimer classes to schedule work as needed.
Leave the idleTimerDisabled
property of the shared UIApplication
object set to NO
wheneverpossible. The idle timer turns off the device’s screen after a specified period of inactivity. If your app doesnot need the screen to stay on, let the system turn it off. If your app experiences side effects as a
result ofthe screen being turned off, you should modify your code to eliminate the side effects rather than disablethe idle timer unnecessarily.
Coalesce work whenever possible to maximize idle time. It generally takes less power to perform a set ofcalculations all at once than it does to perform them in small chunks over an extended period of time.Doing small bits of
work periodically requires waking up the CPU more often and getting it into a statewhere it can perform your tasks.
Avoid accessing the disk too frequently. For example, if your app saves state information to the disk, doso only when that state information changes, and coalesce changes whenever possible to avoid writingsmall changes at frequent
intervals.
Do not draw to the screen faster than is needed. Drawing is an expensive operation when it comes topower. Do not rely on the hardware to throttle your frame rates. Draw only as many frames as your appactually needs.
If you use the UIAccelerometer
class to receive regular accelerometer events, disable the delivery ofthose events when you do not need them. Similarly, set the frequency of event delivery to the smallestvalue that is suitable for your needs. For more information,
see Event Handling Guide for iOS . 

The more data you transmit to the network, the more power must be used to run the radios. In fact, accessingthe network is the most power-intensive operation you can perform. You can minimize that time
by followingthese guidelines:

Connect to external network servers only when needed, and do not poll those servers.

When you must connect to the network, transmit the smallest amount of data needed to do the job. Usecompact data formats, and do not include excess content that simply is ignored.
Transmit data in bursts rather than spreading out transmission packets over time. The system turns offthe Wi-Fi and cell radios when it detects a lack of activity. When it transmits data over a longer period oftime, your app
uses much more power than when it transmits the same amount of data in a shorter amountof time. 
When using the NSURLSession
class to enqueue multiple upload or download tasks, enqueue thoseitems together rather than waiting for one to finish before starting the next one. The system managesautomatically executes queued tasks when it is most efficient
to do so.
Connect to the network using the Wi-Fi radios whenever possible. Wi-Fi uses less power and is preferredover cellular radios.
If you use the Core Location framework to gather location data, disable location updates as soon as youcan and set the distance filter and accuracy levels to appropriate values. Core Location uses the availableGPS, cell, and
Wi-Fi networks to determine the user’s location. Although Core Location works hard tominimize the use of these radios, setting the accuracy and filter values gives Core Location the option toturn off hardware altogether in situations where it is not needed.
For more information, see Location andMaps Programming Guide
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: