ElliotSknr
12/01/2023, 1:47 PMinternal actual class LocationMonitor {
private val _clLocationManger = CLLocationManager()
private class LocationDelegate(
private val onLocationCallback: (CLLocation?) -> Unit,
) : NSObject(), CLLocationManagerDelegateProtocol {
override fun locationManager(manager: CLLocationManager, didUpdateLocations: List<*>) {
// This method stops getting invoked after around 5 updates are sent
val location = (didUpdateLocations.lastOrNull()) as CLLocation?
onLocationCallback(location)
}
/*Other override methods here are also not called e.g. didFailWithError*/
}
init {
_clLocationManger.delegate = LocationDelegate(
onLocationCallback = { location ->
/*Some logic here...*/
}
)
_clLocationManger.requestWhenInUseAuthorization()
_clLocationManger.pausesLocationUpdatesAutomatically = false
_clLocationManger.distanceFilter = kCLDistanceFilterNone
_clLocationManger.desiredAccuracy = kCLLocationAccuracyBestForNavigation
}
actual fun startMonitoring() {
_clLocationManger.startUpdatingLocation()
}
actual fun stopMonitoring() {
_clLocationManger.stopUpdatingLocation()
}
}
I haven't been able to check whether this is fixed in K2 yet, as that'll make my project fail to build due to some third party libraries I'm using.ElliotSknr
12/01/2023, 3:00 PMElliotSknr
12/01/2023, 5:14 PM