gpt4 book ai didi

ios - 位置管理器不会快速更新位置。 AlertView 消失

转载 作者:行者123 更新时间:2023-11-28 13:17:18 25 4
gpt4 key购买 nike

我想快速获取自定义委托(delegate)内的位置。请注意,这在 2 小时前运行良好。主要问题是位置授权 alertView 在我允许之前自行消失。所以我试图进入设置并允许它,但它不起作用。为什么 alertView 会自行消失,为什么即使我通过设置允许它我仍然无法获得更新?我在 plist 中添加了正确的 key ,还在文件中添加了委托(delegate)和 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)")
}
}

最佳答案

locationManager 创建一个属性,因为这样它会在您运行您的方法后被销毁。不要忘记在 viewDidLoad 中设置它的委托(delegate)。

关于ios - 位置管理器不会快速更新位置。 AlertView 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28542193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com