title: App location in background on iOS 8
body: <p>I want get a user's location in app background. It works fine if I use a timer of 9 or less seconds. If I use 10 and more seconds I can't get the user's location...</p>
  
  <p>My <code>AppDelegate.swift</code>:</p>
  
  <pre><code>import UIKit
  import CoreLocation
  
  @UIApplicationMain
  class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
      var window: UIWindow?
      var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid
      var myTimer: NSTimer?
  
      var locationManager = CLLocationManager()
  
      func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
          // Override point for customization after application launch.
          return true
      }
  
      func isMultitaskingSupported() -&gt; Bool {
          return UIDevice.currentDevice().multitaskingSupported
      }
  
      func timerMethod(sender: NSTimer) {
          let backgroundTimerRemainig = UIApplication.sharedApplication().backgroundTimeRemaining
  
          self.locationManager.startUpdatingLocation()
  
          if backgroundTimerRemainig == DBL_MAX {
              println("test1")
          } else {
              println("test")
              self.locationManager.delegate = self
              self.locationManager.startUpdatingLocation()
          }
      }
  
      func applicationWillResignActive(application: UIApplication) {
  
      }
  
      func applicationDidEnterBackground(application: UIApplication){
          if !isMultitaskingSupported() {
              return
          }
  
          myTimer = NSTimer.scheduledTimerWithTimeInterval(60.0,
              target: self,
              selector: "timerMethod:",
              userInfo: nil,
              repeats: true)
  
          backgroundTaskIdentifier = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler {
              () -&gt; Void in
              UIApplication.sharedApplication().endBackgroundTask(self.backgroundTaskIdentifier)
          }
      }
  
      func endBackgroundTask() {
          let mainQueue = dispatch_get_main_queue()
  
          dispatch_async(mainQueue) { 
              [weak self] in
              if let timer = self!.myTimer {
                  timer.invalidate()
                  self!.myTimer = nil
                  UIApplication.sharedApplication().endBackgroundTask(self!.backgroundTaskIdentifier)
                  self!.backgroundTaskIdentifier = UIBackgroundTaskInvalid
              }
          }
      }
  
      func applicationWillEnterForeground(application: UIApplication) {
          if backgroundTaskIdentifier != UIBackgroundTaskInvalid {
              endBackgroundTask()
          }
      }
  
      func applicationDidBecomeActive(application: UIApplication) {
  
      }
  
      func applicationWillTerminate(application: UIApplication) {
          // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
      }
  
      func locationManager(manager: CLLocationManager!, didUpdateToLocation locations: [AnyObject]) {
          var latValue = locationManager.location.coordinate.latitude
          var lonValue = locationManager.location.coordinate.longitude
      }
  }
  </code></pre>
  
  <p>Why can't I get the user's location when I use 10 and more seconds?</p>