gpt4 book ai didi

ios - 如何在 iOS 8 或更早版本上实现 CLLocationManager.requestLocation()?

转载 作者:搜寻专家 更新时间:2023-11-01 07:31:20 25 4
gpt4 key购买 nike

如果您阅读了新的 iOS 9 文档,您可能已经注意到一种新方法,该方法会导致位置管理器在短时间内启动 radio ,修复您的位置并一旦达到所需的精度(或超时)到达后,将其全部关闭,将精确定位的位置交给代表。

该方法称为 CLLocationManager.requestLocation(),在 iOS 9 SDK 中可用。 las,我目前正在开发一个针对 iOS 8 的应用程序,并且仍然非常想使用这种方法。我也不想自己重新实现它。

所以这是我的问题:是否有任何适用于 iOS 的开源库实现这种一次性位置检索?

最佳答案

你需要先执行两个步骤

1) NSLocationWhenInUseUsageDescription

2) NSLocationAlwaysUsageDescription

然后

var locationManager = CLLocationManager()
locationManager.delegate = self
// locationManager.locationServicesEnabled
locationManager.desiredAccuracy = kCLLocationAccuracyBest

let Device = UIDevice.currentDevice()

let iosVersion = NSString(string: Device.systemVersion).doubleValue

let iOS8 = iosVersion >= 8

if iOS8{

locationManager.requestWhenInUseAuthorization()
}
else{
locationManager.requestAlwaysAuthorization()
}

locationManager.startUpdatingLocation()

这会有所帮助。谢谢

关于ios - 如何在 iOS 8 或更早版本上实现 CLLocationManager.requestLocation()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32395514/

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