我已尝试查看其他解决方案,例如:requestWhenInUseAuthorization() not Work in iOS 8 With NSLocationWhenInUseUsageDescription Key in Info.plist
但我无法获得授权以获取位置。
那个人在另一个问题上的问题是他在viewDidLoad
内有经理,我没有,但仍然没有出现授权提示。我已经更新了我的plist:
让我的经理在我的viewDidLoad
之外:
import UIKit
import AVFoundation
import MapKit
class SecondViewController: UIViewController, CLLocationManagerDelegate {
let locationManager: CLLocationManager = CLLocationManager()
var player = AVPlayer()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
println("Got to end of locationmanager")
//playentryaudio() // User plugged in mic -- start playing entry audio.
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
println("Got to locationmngsr")
var userlocation = locations[0] as! CLLocation
var latitude: CLLocationDegrees = userlocation.coordinate.latitude
var longitude: CLLocationDegrees = userlocation.coordinate.longitude
println(latitude)
println(longitude)
} //snip rest of code
由于它没有获得身份验证,因此它永远不会访问locationManager功能。