22
Writing Energy Ecient Code 2014 Session 710 & 712

Battery Saving

Embed Size (px)

DESCRIPTION

Principles from WWDC 2014 Session 710 and 712 in iOS development. To save your battery life is major concern since user could check the battery usage in iOS8. Those battery master will be deleted forever, and you are no longer be able to blame the reason of draining on other apps (Map/Facebook).

Citation preview

Page 1: Battery Saving

Writing Energy Efficient Code

2014 Session 710 & 712

Page 2: Battery Saving

What Uses Energy?

Page 3: Battery Saving

Concept

Coalesce work

Cut down wakes

Page 4: Battery Saving
Page 5: Battery Saving
Page 6: Battery Saving

“To sleep is the prepare for the longer journey ahead”

Page 7: Battery Saving

Preview

Page 8: Battery Saving

Do It Never

Page 9: Battery Saving

Do it never

• Avoid unneeded work

Respond to changes in active state

Page 10: Battery Saving

Do it neverLocation

“Stop Location Updates”

Page 11: Battery Saving

Do it at better time

• NSURLSession Background Session

• Understand requirements

• Overhead cost

Let the system schedule work

Page 12: Battery Saving

Do it at better timeNSURLSession - Discretionary Tasks

Page 13: Battery Saving

Do It at Better Time

Page 14: Battery Saving

• Network conditions Throughput

• Reduce data sizes Quality, Compress

• Avoid redundant transfers Caching, Resumable

• Handle errors Timeout, Retry

Do it at better timeNetworking

Page 15: Battery Saving

Do It More Efficiently

Page 16: Battery Saving

Do it more efficiently

Quality of Service NSOperation and NSOperationQueue

Specify QoS classes on your work

Page 17: Battery Saving

• Specify the responsiveness and energy requirements of work.

• Classify long-running or resource-intensive operations in your existing code.

• Aim for >90% of time at Utility or below when the user is inactive.

Do it more efficientlyQuality of Service

Page 18: Battery Saving

Do It Less

Page 19: Battery Saving

Do it less

• Reduce CPU Use minimize timers• Performance Unit Test (Prince)

• Limit Screen Updates• Visual effects avoid placing over updates elements

• Minimize your I/O

Optimize and improve your resource use

Page 20: Battery Saving

Do it less

• Device will wake for notifications

• Set Push notification priority

Notifications

Page 21: Battery Saving

Summary

“Be a considerate background app”

Page 22: Battery Saving

Related

2013 Session 712 Energy Best Practices