Hey yall--seemingly once in a blue moon whenever fetchLocation gets called in here from a widget that is requesting location, it calls on the manager's requestLocation, the widget will crash. Crash stack backtrace shows this:
And this is the affected code:
import Foundation
import CoreLocation
class WidgetLocationFetcher: NSObject, CLLocationManagerDelegate {
let manager = CLLocationManager()
private var handler: ((CLLocation?) -> Void)?
override init() {
super.init()
DispatchQueue.main.async {
self.manager.delegate = self
self.manager.requestWhenInUseAuthorization()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.handler?(locations.last!)
self.handler = nil
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error)
self.handler?(nil)
self.handler = nil
}
func fetchLocation(handler: @escaping (CLLocation?) -> Void) {
self.handler = handler
self.manager.requestLocation()
}
}
I am not too sure what could even be causing this, although I am running watchOS 10 beta 8 and iPadOS 17 beta 8 on the devices experiencing this crash. Has anyone ever solved this issue?