未使用 plist 条目调用 CLLocationManager didUpdateLocations iOS 8
CLLocationManager didUpdateLocations not being called iOS 8 with plist entries
我在使用 CLLocationManager 时遇到了一些问题。此代码曾经在 iOS 8.2 上工作,但自从升级到 8.3 后就不再工作了。这是设置启动时调用的位置管理器的代码。
let distanceThreshold:CLLocationDistance = 100.0
var currentLocation:CLLocationCoordinate2D?
override init() {
assert(locMan == nil)
super.init()
locMan = self
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
currentLocation = manager.location.coordinate
if UIApplication.sharedApplication().applicationState == .Background {
PlacesManager.fetchNearbyPlaces(LocationManager.getLocationManager().currentLocation!, radius: distanceThreshold, callback: placesCallback)
}
}
使用此代码,didUpdateLocations 从未被调用过,尽管它之前被调用过。
我已将相关条目添加到 Info.plist 文件中:
我在设备和模拟器上都试过了,但都不行。事实上,如果我删除应用程序并重新安装,它似乎不再请求位置授权。
我知道我错过了一些愚蠢的东西,但我无法锻炼它到底是什么。
如果有人能提供任何帮助,我将不胜感激。
干杯,
杰拉德
安娜的回答:
CLLocationManager 文档说:"To configure and use a CLLocationManager object to deliver events...Create an instance of the CLLocationManager class and store a strong reference to it somewhere in your app. Keeping a strong reference to the location manager object is required until all tasks involving that object are complete. Because most location manager tasks run asynchronously, storing your location manager in a local variable is insufficient."
除了接受的答案,如果您使用的是模拟器。您必须 select 在 应用程序 运行 之后 一个位置(调试->位置->苹果总部)。我设置了位置并假设下一次 运行 应用程序 didUpdateLocations
将使用我之前设置的内容调用,但该假设是错误的。
我在使用 CLLocationManager 时遇到了一些问题。此代码曾经在 iOS 8.2 上工作,但自从升级到 8.3 后就不再工作了。这是设置启动时调用的位置管理器的代码。
let distanceThreshold:CLLocationDistance = 100.0
var currentLocation:CLLocationCoordinate2D?
override init() {
assert(locMan == nil)
super.init()
locMan = self
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
currentLocation = manager.location.coordinate
if UIApplication.sharedApplication().applicationState == .Background {
PlacesManager.fetchNearbyPlaces(LocationManager.getLocationManager().currentLocation!, radius: distanceThreshold, callback: placesCallback)
}
}
使用此代码,didUpdateLocations 从未被调用过,尽管它之前被调用过。
我已将相关条目添加到 Info.plist 文件中:
我在设备和模拟器上都试过了,但都不行。事实上,如果我删除应用程序并重新安装,它似乎不再请求位置授权。
我知道我错过了一些愚蠢的东西,但我无法锻炼它到底是什么。
如果有人能提供任何帮助,我将不胜感激。
干杯, 杰拉德
安娜的回答:
CLLocationManager 文档说:"To configure and use a CLLocationManager object to deliver events...Create an instance of the CLLocationManager class and store a strong reference to it somewhere in your app. Keeping a strong reference to the location manager object is required until all tasks involving that object are complete. Because most location manager tasks run asynchronously, storing your location manager in a local variable is insufficient."
除了接受的答案,如果您使用的是模拟器。您必须 select 在 应用程序 运行 之后 一个位置(调试->位置->苹果总部)。我设置了位置并假设下一次 运行 应用程序 didUpdateLocations
将使用我之前设置的内容调用,但该假设是错误的。