I just followed http://www.raywenderlich.com/92428/background-modes-ios-swift-tutorial location update part.
But manager doesn't print location info in background mode.
Then manager print logs to Xcode's console when app enter foreground.
Is this code right?
import UIKit
import CoreLocation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var window: UIWindow?
var manager = CLLocationManager()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.delegate = self
manager.requestAlwaysAuthorization()
manager.startUpdatingLocation()
return true
}
func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
if UIApplication.sharedApplication().applicationState != .Active {
NSLog("App is backgrounded. New location is %@", newLocation)
}
}
.....
}