I am using the iOS SDK 8.1, trying to call the requestWhenInUseAuthorization () method to invite the user to grant access to my application. I imported CoreLocation.framework and added the NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription keys to info.plist. When I launched the application, it never asked me for access to the location. Below is my code, what did I miss?
import UIKit import CoreLocation import MapKit class ViewController: UIViewController, CLLocationManagerDelegate { override func viewDidLoad() { super.viewDidLoad() var manager = CLLocationManager() manager.delegate = self manager.desiredAccuracy = kCLLocationAccuracyBest let authorizationStatus = CLLocationManager.authorizationStatus() switch authorizationStatus { case .Authorized: println("authorized") case .AuthorizedWhenInUse: println("authorized when in use") case .Denied: println("denied") case .NotDetermined: println("not determined") case .Restricted: println("restricted") } manager.requestWhenInUseAuthorization() manager.startUpdatingLocation() } func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { let location = locations[0] as CLLocation println("Latitude: \(location.coordinate.latitude). Longitude: \(location.coordinate.longitude).") } func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) { switch status { case .Authorized: println("authorized") case .AuthorizedWhenInUse: println("authorized when in use") case .Denied: println("denied") case .NotDetermined: println("not determined") case .Restricted: println("restricted") } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
The console only showed "undefined" once and nothing more. So I went to iPhone Simulator => Settings => Privacy => Location => My application. He showed me 3 options: “Never”, “When using the application”, “Always”. But nothing was chosen.
ios8 swift core-location
toadead Dec 29 '15 at 0:12 2014-12-29 00:12
source share