It appears there is some sort of issue in Kotlin 1...
# multiplatform
e
It appears there is some sort of issue in Kotlin 1.9.X re; the location manager updates suddenly stopping I've tried using Kotlin 1.9.20 and 1.9.21. It looks like this was working on Kotlin 1.8.X as confirmed by Charlie here https://kotlinlang.slack.com/archives/C3PQML5NU/p1700504325604049
Copy code
internal 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.
I've opened an issue here KT-63992, here's to hoping this gets looked at soon
Disabling GC with freeCompilerArgs += "-Xgc=noop" fixes the issue. Not ideal but a temporary workaround while this gets fixed
👍 1