1

I'm trying to reduce my application's battery usage. I'd like to use Xcode tools or instruments to measure before and after to verify I've made an improvement.

I'm having trouble measuring the basics. I want to verify that I am only measuring location on the screen that needs it. The trouble is instrumentation thinks I'm always using the device's GPS/location.

When I use instruments to monitor the process, it shows gps as always on:

enter image description here

So does xcode's energy monitor:

enter image description here

I'm measuring on a real device, and I have tried:

  • Never tracking in my code (comment out locationManager.startUpdatingLocation())
  • Shut down other background apps that might be using location "while using"
  • Denied permission for all apps that want location "Always"
  • Disabled frameworks I depend on (Hockey, Mixpanel) that might be using location

Still the instrumentation shows constant location usage.

The only 2 things that cause the GPS to show it's been turned off are:

  • Disabling all location services for the phone
  • Swiping up from the bottom of the phone to show the settings screen for toggling bluetooth, wifi, and airplane mode. (I don't have to do anything, just show the screen)

The first section is starting without location services on for the phone at all, and the second green section is swiping up to show the settings panel:

enter image description here

Any idea what might be going on?

Xcode/Instruments 7.3

SimplGy
  • 20,079
  • 15
  • 107
  • 144

1 Answers1

1

Found it, thanks to this answer.

I also have a mapView on the screen, and it tracks the user's location. This is totally separate from my other location monitoring and I didn't realize it.

Setting mapView.showsUserLocation = false in viewWillDissappear stops the GPS usage, which is great.

I'm now working on how to re-use the location from the map instead of creating my own separate monitor (and also lower the accuracy and frequency of the map location).

Community
  • 1
  • 1
SimplGy
  • 20,079
  • 15
  • 107
  • 144
  • If anybody follows this later, it seems right now there's no way to lower the resolution (meters) or sampling rate of `MKMapView`, you just sign up for updates and get what you get. – SimplGy Apr 25 '16 at 19:07