
The Power Games
If we compare app development with film making then a beautiful UI and a great user experience(UX) are the main cast. And like film making there are some crew members working behind the scene, work to make our main cast look better than the best. In app world, some of the main back stage crew members are responsive UI, optimised network usage and less battery drain.
Battery is the biggest pain point of any smartphone user. And now a days, users have learnt how to save their smartphone’s battery. iOS makes smart decisions about how to utilize the resources and run code as efficiently as possible. But at the time of developing an app with beautiful animation or working under tight timelines, we often forget to focus on these factors and apparently it takes a toll on UX. Alternatively user will stop giving you permissions to access location, background activities etc. Again not good UX in your app.

The culprits of excessive energy consumptions are CPU, Networking Operations, Location and Motion Updates, Bluetooth. Whether we play a video or just make any update on UI, anything and everything drains the battery. There are many practices by which we can contribute to the overall energy efficiency of the platform. Let’s look into those one by one.
Background Activities
- App should work in background as minimal as possible and whenever it does, we should notify the system when we are done with our task.
- The system prioritises the tasks and we should help it by providing the right priorities to our NSOperation, NSOperationQueue, NSThread, dispatch queues.
- We should minimise the use of timers. We can use event notifications or GCD tools for synchronisation. If it is a must to use timers then we should maximise the time intervals and invalidate it when done.
- File operations should also be minimized. One should rather opt for a database in case one need frequent transactions.
User Interface
- Every UI update requires CPU, GPU and of course and active screen. We should try to reduce the number of views, use of opacity and blur. We should use low and consistent frame rate for UI updates.
- Adding any layers over full screen video (e.g elements to control video payback) should be avoided or we can try to remove these when user is not interacting with them.
- We should use darker colours because brighter colour required higher energy to display. We should keep media sizes small.
Networking
- Batching is a bliss for network operations. We should try to batch and reduce these operations. We can also minimise the data sizes by compression, avoid redundant transfers, cache data and use resumable transfers. Signal strength is also important. Poor signal and low bandwidth results in draining the battery.
- We should not overuse push notification. Try to use the deferred delivery method instead of immediate delivery priority to help system optimise performance. A possible alternative can be local notifications based on the use case you have.
- VoIP apps can use PushKit framework instead of persistent connections. PushKit awakes device when VoIP occurs whereas persistent connections keep sending messages to keep it alive even when the call is not active.

Motion
- Avoid continuous motion updates if its not a must do thing. Try to specify the higher time interval for updates.
- Improper and unnecessary use of location can prevent the device from sleeping and keep location hardware powered up. Request location, use it and stop location service. We can reduce the accuracy of standard location updates and stop location updates if accuracy does not match expectation. We should defer location updates when running in the background. Use the region and beacon monitoring when we need entry and exit notifications from specific location. Also, we can register for significant change location update instead of continuous updates when GPS-level accuracy isn’t critical for the operations.
External Devices
- We should be more careful in interacting with bluetooth devices because it consumes energy on both devices. We should scan for bluetooth devices when needed. We should minimise the processing of all kind of devices. Try to look for specific (required) services and characteristics.
- We should minimise the traffic between the smart watch and phone as it impacts both device’s battery. Apple has introduced a Watch Connectivity API for optimized data transfers. We should reduce network activity on watch and batch transactions together. We should do less work on Watch and perform expensive operations on phone and use the result in watch.

Low Power Mode
We should register for power state notifications for low power mode and stop any high power consuming tasks.
We as a developer, should make sure that we take every step possible to remove even small inefficiencies because these adds up and significantly affect battery life, performance and responsiveness.

