【Topics Power】Reduce Power Consumption

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值