magnumrocha
06/12/2024, 8:24 PMNWPathMonitor
on ios kotlin code? I can't find a way to import it to use...Pablichjenkov
06/12/2024, 8:30 PMmagnumrocha
06/13/2024, 6:23 AMmagnumrocha
06/13/2024, 6:24 AMmagnumrocha
06/13/2024, 6:24 AMPablichjenkov
06/13/2024, 6:39 AMwrapper
way.magnumrocha
06/13/2024, 7:01 AMMJegorovas
06/13/2024, 9:06 AMNWPathMonitor
class in Swift-only, it is really only a wrapper around C code which has obj-c typealias nw_path_monitor_t. Here's a sample of very basic usage:
actual class NetworkStatus {
private val monitor = nw_path_monitor_create()
private var path: nw_path_t = null
init {
nw_path_monitor_set_queue(monitor, dispatch_get_global_queue(QOS_CLASS_BACKGROUND.toLong(), 0u))
nw_path_monitor_set_update_handler(monitor) { path ->
this.path = path
}
nw_path_monitor_start(monitor)
}
actual fun isNetworkAvailable(): Boolean = nw_path_get_status(path) == nw_path_status_satisfied
}