Chapter 3. Energy

With mobile devices becoming ubiquitous, battery life has become an important factor influencing which devices consumers ultimately purchase. Similarly, power consumption is an important factor that influences the decision of whether to install an app.

Each hardware component on the device consumes power. The primary consumer of power is the CPU, but that is only one side of the system. A well-written app is vigilant about using energy sparingly. Apps that drain the battery quickly tend to get deleted by users.

Aside from the CPU, noteworthy hardware components that consume battery life include network hardware, Bluetooth, GPS, and the microphone, accelerometer, camera, speaker, and screen.

In this chapter, we focus on key areas that contribute to power consumption and how we can minimize the consumption. We will learn how to write an app that is aware of the battery level of the device and its charging state. We will also learn how to analyze power, CPU, and resource usage in an iOS app.

CPU

The central processing unit (CPU) is the primary hardware used by an app, either when it is directly being used by the user or indirectly, during background operations and when processing push notifications.

The processors used for the iPhone (5, 5S, and 6) and iPad (3, 4, and Air) are either dual-core or tri-core. See Table 3-1 for the complete list. The Geekbench scores reflect the relative computing speed of the processors on these popular and recent iOS devices.

Get High Performance iOS Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.