Skip to content

Reachable

Reachable is a Kotlin Multiplatform library that tells you whether the device is on the internet, and lets you observe changes as they happen. It targets iOS, iPadOS, macOS, and Android, and presents the same API to Kotlin and Swift consumers.

// Singleton — no Context plumbing, callable from anywhere.
val reachability: Reachability = Reachability.shared

if (reachability.isReachable) {
    // online
}

reachability.status.collect { status ->
    // every state change
}

From Swift:

let reachability: any Reachability = Reachability.shared

status.value for a synchronous read, status.collect {} for a reactive listener, status.first() for a one-shot suspend. isReachable and isDataMetered are shortcuts for the two most common axes; see Concepts → API design.

For explicit lifecycle (tests, per-feature observers), use the platform factories Reachability(context) / Reachability() instead.

Targets

  • iOS 18, iPadOS 18, macOS 15. ARM only (iosArm64, iosSimulatorArm64, macosArm64).
  • Android 11 (API 30). arm64-v8a only.

Implementation

Apple uses the Network framework's nw_path_monitor C API via Kotlin/Native cinterop. Android uses ConnectivityManager.NetworkCallback against a NetworkRequest requiring NET_CAPABILITY_INTERNET and NET_CAPABILITY_VALIDATED, which is the only capability pair that distinguishes a working network from a captive portal.

Apple's nw_path_is_expensive and nw_path_is_constrained (cellular, hotspot, and Low Data Mode) both fold into isDataMetered. Android uses NET_CAPABILITY_NOT_METERED for the same signal.

The Swift surface is generated by SKIE: enums become exhaustive Swift enums, StateFlow<T> becomes AsyncSequence<T>, suspend fun becomes async throws.

Install

From Maven Central (Android, JVM, Kotlin Multiplatform):

implementation("com.happycodelucky.reachable:reachable:0.12.11")

Apple consumers come in via Kotlin Multiplatform's iOS / macOS klibs published alongside the Android AAR. A native Swift Package Manager distribution is planned for v0.2. See Installation.