Is it possible to use `NWPathMonitor` on ios kotl...
# ios
m
Is it possible to use
NWPathMonitor
on ios kotlin code? I can't find a way to import it to use...
p
Is it obj-c compatible?
m
image.png
good point.... didn't checked that yet....
I think it's only present on Swift
blob shrug 1
p
In such a case you would have to go the
wrapper
way.
m
yes, thanks for the help
👍 1
m
While
NWPathMonitor
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:
Copy code
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
}
👀 2