我尝试寻找其他解决方案,例如: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 函数。
最佳答案
提示仅在 CLLocationManager.authorizationStatus() == .NotDetermined
时显示。如果用户之前拒绝访问,您将不会再看到提示。您应该在 self.locationManager.requestWhenInUseAuthorization()
之前检查状态。如果它显示除 .NotDetermined
之外的任何内容,请查看应用和设备的位置设置。
如果状态为 .NotDetermined
并且提示仍未显示,我会仔细检查 NSLocationWhenInUseUsageDescription
的拼写。
关于ios - 没有获得位置 iOS8 的授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32169210/