From 5b253a3b66f1015fe88e4ab6e914621e7af851bf Mon Sep 17 00:00:00 2001 From: Bruno Bowden Date: Sat, 18 Oct 2014 11:29:01 -0700 Subject: [PATCH 1/2] Suggest PRs for errata + ignore Xcode user settings --- .gitignore | 3 +++ README.md | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c01e32c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +# Xcode user settings +**/xcuserdata/ diff --git a/README.md b/README.md index 873fcf0..44f1fda 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,9 @@ http://shop.oreilly.com/product/0636920034254.do If you have any questions, you can contact me directly at vandad.np@gmail.com -Similarly, if you find an error in these sample codes, simply -report them to O'Reilly at the following URL: + +If you find an error in these code samples, please fork the Github +repository and submit a pull request with the improvements. + +You can also report errors on the O’Reilly website: http://www.oreilly.com/catalog/errata.csp?isbn=0636920034254 \ No newline at end of file From e7ba498ac48f1e484e32fe83cbe85f8c1689035b Mon Sep 17 00:00:00 2001 From: Bruno Bowden Date: Sat, 18 Oct 2014 11:29:49 -0700 Subject: [PATCH 2/2] iOS 8 fix for Handling Location Changes in the Background MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call requestAlwaysAuthorization() Add and logging to help explain what’s going on --- .../AppDelegate.swift | 36 +++++++++++-------- .../Info.plist | 2 ++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/chapter-concurrency/Handling Location Changes in the Background/Handling Location Changes in the Background/AppDelegate.swift b/chapter-concurrency/Handling Location Changes in the Background/Handling Location Changes in the Background/AppDelegate.swift index eb383e5..151185d 100644 --- a/chapter-concurrency/Handling Location Changes in the Background/Handling Location Changes in the Background/AppDelegate.swift +++ b/chapter-concurrency/Handling Location Changes in the Background/Handling Location Changes in the Background/AppDelegate.swift @@ -26,33 +26,47 @@ import CoreLocation @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, +// The following is the protocol for location updates CLLocationManagerDelegate { var window: UIWindow? var locationManager: CLLocationManager! = nil var isExecutingInBackground = false -func locationManager(manager: CLLocationManager!, - didUpdateToLocation newLocation: CLLocation!, - fromLocation oldLocation: CLLocation!){ - if isExecutingInBackground{ + // LocationManager will call this handler for all location updates + func locationManager(manager: CLLocationManager!, + didUpdateToLocation newLocation: CLLocation!, + fromLocation oldLocation: CLLocation!) { + + if (newLocation != nil) { + println("New Location: \(newLocation.coordinate.latitude), \(newLocation.coordinate.longitude)") + } + if isExecutingInBackground { /* We are in the background. Do not do any heavy processing */ } else { /* We are in the foreground. Do any processing that you wish */ } -} + } func application(application: UIApplication, - didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { + didFinishLaunchingWithOptions + launchOptions: NSDictionary?) -> Bool { + locationManager = CLLocationManager() locationManager.desiredAccuracy = kCLLocationAccuracyBest + + // Uses CLLocationManagerDelegate protocol locationManager.delegate = self + + // Asks user for app permission to receive background location changes + locationManager.requestAlwaysAuthorization() + + // This can be called immediately but not updates will not + // be received until the user has approved access locationManager.startUpdatingLocation() return true } - - func applicationDidEnterBackground(application: UIApplication) { isExecutingInBackground = true @@ -68,11 +82,5 @@ func locationManager(manager: CLLocationManager!, detection accuracy */ locationManager.desiredAccuracy = kCLLocationAccuracyBest } - - - - - - } diff --git a/chapter-concurrency/Handling Location Changes in the Background/Handling Location Changes in the Background/Info.plist b/chapter-concurrency/Handling Location Changes in the Background/Handling Location Changes in the Background/Info.plist index fdb84af..e02d6ff 100644 --- a/chapter-concurrency/Handling Location Changes in the Background/Handling Location Changes in the Background/Info.plist +++ b/chapter-concurrency/Handling Location Changes in the Background/Handling Location Changes in the Background/Info.plist @@ -4,6 +4,8 @@ CFBundleDevelopmentRegion en + NSLocationAlwaysUsageDescription + <Message to explain why app needs always on location> CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier