Power consumption Source:

  • CPU;
  • Network;
  • Positioning;
  • The image.

.

.

How to optimize:

1. Minimize CPU and GPU power consumption.

2. Use less timers;

3. Optimize I/O operations:

  • Try not to frequently write small data, it is best to batch write at a time;
  • Consider dispatch_io for reading and writing large amounts of important data, which provides an API for asynchronously operating file I/O based on GCD. Dispatch_io optimizes disk access;
  • For a large amount of data, you are advised to use databases (such as SQLite and CoreData).

4. Network optimization

  • Reduce and compress network data;
  • If the result of multiple requests is the same, try to use caching;
  • Use breakpoint continuation, otherwise the same content may be transmitted multiple times when the network is unstable
  • Do not attempt to perform network requests when the network is unavailable;
  • Users can cancel long running or slow network operations and set appropriate timeouts;
  • For example, when downloading video streams, instead of sending small packets, download the entire file directly or in large chunks. If you download ads, download several at a time and display them slowly. If you download emails, download several at a time, not one by one.

5. Positioning optimization:

  • This works best if you just need to quickly locate the userCLLocationManagertherequestLocationMethods. After the positioning is completed, the positioning hardware will be automatically powered off.
  • If it’s not a navigation app, try not to update your location in real time. Turn off location services when you’re done.
  • Minimize positioning accuracy, for example, try not to use the highest accuracykCLLocationAccuracyBest;
  • If background positioning is required, set it as far as possiblepausesLocationUpdatesAutomaticallyforYESIf the user is unlikely to move the system will automatically pause position updates;
  • Try not to makestartMonitoringSignificantLocationChangesGive priority tostartMonitoringForRegion:(This method is triggered only if the user’s position has been moved).

6. Hardware detection optimization:

When the user moves, shakes or tilts the device, motion events are generated, which are detected by hardware such as accelerometers, gyroscopes and magnetometers. These hardware should be turned off when testing is not required.