After updating my project with 100.3, my autoPanModeChangedHandler is no longer called. I made a test app with basically the same swift code from the [ArcGIS Runtime SDK Samples]->[Display device location] and it doesn't fire there either. Does anyone know if the way we should use autoPanModeChangedHandler has changed?
Solved! Go to Solution.
Worth Sparks,
I can reproduce this. I've put an issue in and we'll get it fixed in the next release. In the mean time, would you be able to use KVO in place of the autoPanModeChangedHandler?
You can add an observer:
mapView.locationDisplay.addObserver(self, forKeyPath: "autoPanMode", options: [.new, .old], context: &myContext)
And then write the function that gets called when a change happens:
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if context == &myContext {
if let newValue = change?[NSKeyValueChangeKey.newKey], let oldValue = change?[NSKeyValueChangeKey.oldKey], let prop = keyPath, let sender = object {
print("\(type(of: (sender) as AnyObject)) - \(prop) changed: \(newValue) old value: \(oldValue)")
DispatchQueue.main.async {
// Do any UI work on the main thread.
}
}
else {
print("context matched but some value was null")
}
} else {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
}
}
You'll need to remove the observer:
deinit {
mapView.locationDisplay.removeObserver(self, forKeyPath: "autoPanMode")
}
One way to create a variable for the context is:
private var myContext = 0
I didn't use the new Swift mapView.locationDisplay.observe syntax because of this Swift bug [SR-5872] newValue and oldValue always nil when observing AVPlayerItem.status - Swift As far as I can tell it is still a bug but might be worth a try with the latest version.
Thanks,
Phil
Worth Sparks,
I can reproduce this. I've put an issue in and we'll get it fixed in the next release. In the mean time, would you be able to use KVO in place of the autoPanModeChangedHandler?
You can add an observer:
mapView.locationDisplay.addObserver(self, forKeyPath: "autoPanMode", options: [.new, .old], context: &myContext)
And then write the function that gets called when a change happens:
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if context == &myContext {
if let newValue = change?[NSKeyValueChangeKey.newKey], let oldValue = change?[NSKeyValueChangeKey.oldKey], let prop = keyPath, let sender = object {
print("\(type(of: (sender) as AnyObject)) - \(prop) changed: \(newValue) old value: \(oldValue)")
DispatchQueue.main.async {
// Do any UI work on the main thread.
}
}
else {
print("context matched but some value was null")
}
} else {
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
}
}
You'll need to remove the observer:
deinit {
mapView.locationDisplay.removeObserver(self, forKeyPath: "autoPanMode")
}
One way to create a variable for the context is:
private var myContext = 0
I didn't use the new Swift mapView.locationDisplay.observe syntax because of this Swift bug [SR-5872] newValue and oldValue always nil when observing AVPlayerItem.status - Swift As far as I can tell it is still a bug but might be worth a try with the latest version.
Thanks,
Phil
I just transitioned my code to KVO on autoPanMode and it works great. It isn't as elegant as autoPanModeChangedHandler but it makes an awesome workaround for until the fix comes.
Thanks Phil.
Worth