如何在 iOS 8 或更早版本上实施 CLLocationManager.requestLocation()?
How to implement CLLocationManager.requestLocation() on iOS 8 or older?
如果您阅读了新的 iOS 9 文档,您可能已经注意到一种新方法,该方法会导致位置管理器在短时间内启动无线电,修复您的位置并一次达到所需的精度(或超时),将其全部关闭,将精确定位的位置移交给代表。
该方法称为 CLLocationManager.requestLocation()
并且在 iOS 9 SDK 中可用。 las,我目前正在开发一个针对 iOS 8 的应用程序,并且仍然非常想使用这种方法。我也不想自己重新实现它。
所以这是我的问题:是否有用于 iOS 实现这种一次性位置检索的开源库?
正如 Arslan Asim 指出的那样,一个好的解决方案是使用 INTULocationManager.
来自文档:
manager.requestLocationWithDesiredAccuracy(.Block, timeout: 10.0) {
(currentLocation, achievedAccuracy, status) in
// Examine status to see if the request timed out.
// If not, currentLocation stores the found location.
}
您需要先执行两个步骤
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()
这将Help.Thanksyou
如果您阅读了新的 iOS 9 文档,您可能已经注意到一种新方法,该方法会导致位置管理器在短时间内启动无线电,修复您的位置并一次达到所需的精度(或超时),将其全部关闭,将精确定位的位置移交给代表。
该方法称为 CLLocationManager.requestLocation()
并且在 iOS 9 SDK 中可用。 las,我目前正在开发一个针对 iOS 8 的应用程序,并且仍然非常想使用这种方法。我也不想自己重新实现它。
所以这是我的问题:是否有用于 iOS 实现这种一次性位置检索的开源库?
正如 Arslan Asim 指出的那样,一个好的解决方案是使用 INTULocationManager.
来自文档:
manager.requestLocationWithDesiredAccuracy(.Block, timeout: 10.0) {
(currentLocation, achievedAccuracy, status) in
// Examine status to see if the request timed out.
// If not, currentLocation stores the found location.
}
您需要先执行两个步骤
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()
这将Help.Thanksyou