【发布时间】:2015-02-16 13:11:45
【问题描述】:
我想快速获取自定义委托中的位置。请注意,这在 2 小时前运行良好。主要问题是位置授权警报视图在我允许它之前自行消失。所以我试图进入设置并允许它,但它不起作用。为什么 alertView 会自行消失,为什么即使我通过设置允许它仍然无法获得更新?我在 plist 中添加了正确的键,还在文件中添加了委托和 CoreLocation 框架。另请注意,在任何时候都不会调用 didFail。任何建议将不胜感激
func getLocation(){
println("called")
let locationManager:CLLocationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
let status = CLLocationManager.authorizationStatus()
println(status.rawValue)
if(status != CLAuthorizationStatus.Authorized) {
locationManager.requestWhenInUseAuthorization()
println("called2")
}else{
locationManager.startUpdatingLocation()
println("allowed and updating")
}
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
println("updating")
var locationArray = locations as NSArray
var locationObj = locationArray.lastObject as CLLocation
println(locationObj)
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
println(error)
}
func locationManager(manager: CLLocationManager!,
didChangeAuthorizationStatus status: CLAuthorizationStatus) {
var shouldIAllow = false
println(status)
switch status {
case CLAuthorizationStatus.Restricted:
println("Restricted Access to location")
case CLAuthorizationStatus.Denied:
println("User denied access to location")
case CLAuthorizationStatus.NotDetermined:
println("Status not determined")
default:
println("Allowed to location Access")
shouldIAllow = true
}
if (shouldIAllow == true) {
manager.startUpdatingLocation()
} else {
println("Denied access: \(status)")
}
}
【问题讨论】:
标签: ios xcode swift core-location cllocationmanager