In the end, I used Koin and an interface to use a native iOS code:
class SystemInfoImpl: SystemInfo {
func getDeviceUptime() -> Int64 {
var uptime = timespec()
if clock_gettime(CLOCK_MONOTONIC_RAW, &uptime) == 0 {
return Int64(uptime.tv_sec) * 1000 + Int64(uptime.tv_nsec / 1000000)
}
return -1
}
}
➕ 1
p
Pablichjenkov
05/07/2024, 4:04 PM
You can always bridge to the platform native API, that's the strength of KMP but wonder if
org.jetbrains.kotlinx:kotlinx-datetime
works for you?
p
Pat Snow
05/08/2024, 8:24 AM
Hi Pablichenko. I've checked the docs for
datetime
but haven't seen any references to system uptime or boot timestamp.
p
Pablichjenkov
05/08/2024, 1:03 PM
Ah I see, I initially thought you wanted to measure just time elapsed. But not specifically system uptime. Actually I thought this was possible too but doesn't seem to be the case 😕