title: Swift - Turning location on and off in the background to save battery
body: <p>Questions in this vein are asked a lot on this site, but they're all filled with confusion or out of date answers, and I was wondering if anyone could give me a definitive answer as to how to solve the problem in my case? I'd like to update the location in the background somewhat frequently, but turn off location services when uneeded so that power is saved. 
  So I have periodic background updates working 
       as such </p>
  
  <pre><code> func applicationWillResignActive(application: UIApplication) {
    NSNotificationCenter.defaultCenter().postNotificationName(BeginBackGroundMode, object:self)
  
  }
  </code></pre>
  
  <p>This function this notification calls ncludes this - </p>
  
  <pre><code>locationManager.pausesLocationUpdatesAutomatically = false
  timer = NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: Selector("onTick"), userInfo: nil, repeats: true)         
  </code></pre>
  
  <p>so this is repeated in the background </p>
  
  <pre><code>  func onTick(){
      println("ticking")  
      println("\(Coordinates!.latitude)")
      println( "\(Coordinates!.longitude)")
  
  
      self.locationManager.allowDeferredLocationUpdatesUntilTraveled(CLLocationDistanceMax, timeout: 4)
  
  
  
  }
  
    func locationManager(manager: CLLocationManager!,didFinishDeferredUpdatesWithError error: NSError!) {
      locationManager.startUpdatingLocation()
  
  
  
  }
  </code></pre>
  
  <p>This works, but I feel like I might not be going about it the right way, so any improvements in code elegance or understanding would be awesome. As for my question, where in the process should I turn location on and off to save battery? Or are there other way's you'd reccomend saving battery? (I need max accuracy). 
  Thanks in advance</p>