NetPulseKit is a lightweight iOS Swift Package that monitors network quality in real time.
It combines real signals available to normal iOS apps:
- connectivity status (
NWPathMonitor) - active interface type
- expensive/constrained path flags
- periodic latency probes via
URLSession - estimated packet loss from rolling probe failures
Most apps only track online/offline state. NetPulseKit helps you react to quality shifts (for example, reducing bitrate, delaying large syncs, or softening retry policies) using a pragmatic, deterministic model.
NetPulseKit does not claim exact OS-reported packet loss or jitter telemetry.
packetLossPercent is an estimate based on a rolling window of probe success/failure outcomes. This is intentional and explicit in the API.
In Xcode:
File→Add Packages...- Enter your repository URL
- Add
NetPulseKitto your target
Or in Package.swift:
dependencies: [
.package(url: "https://github.com/your-org/NetPulseKit.git", from: "1.0.0")
],
targets: [
.target(
name: "YourApp",
dependencies: ["NetPulseKit"]
)
]Add this to your Podfile:
platform :ios, '15.0'
target 'YourApp' do
use_frameworks!
pod 'NetPulseKit', '~> 1.0'
endThen run:
pod installimport NetPulseKit
let monitor = NetworkQualityMonitor()
monitor.onUpdate = { snapshot in
print("Grade:", snapshot.grade)
print("Latency:", snapshot.latencyMs ?? 0)
print("Estimated Loss:", snapshot.packetLossPercent ?? 0)
}
monitor.start()Task {
for await snapshot in monitor.updates {
print(snapshot)
}
}import Combine
import NetPulseKit
var cancellables = Set<AnyCancellable>()
monitor.publisher
.sink { snapshot in
print(snapshot.grade)
}
.store(in: &cancellables)import NetPulseKit
let model = NetworkQualityObservableModel()
model.start()Use model.snapshot in your SwiftUI layer via @StateObject or @ObservedObject.
import NetPulseKit
let config = NetworkQualityConfiguration(
probeURL: URL(string: "https://www.apple.com/library/test/success.html")!,
probeInterval: 5,
requestTimeout: 3,
rollingSampleSize: 20,
latencyThresholds: .init(
excellentMaxMs: 120,
goodMaxMs: 300,
fairMaxMs: 800,
poorMinMs: 800
),
enableLogging: false
)
let monitor = NetworkQualityMonitor(configuration: config)ConnectivityStatus:.online,.offline,.requiresConnectionNetworkInterfaceKind:.wifi,.cellular,.wiredEthernet,.loopback,.other,.unknownNetworkQualityGrade:.offline,.poor,.fair,.good,.excellentNetworkQualitySnapshot: full point-in-time signal bundleNetworkQualityConfiguration: probe + thresholds + estimator tuningNetworkQualityMonitor: façade with closure,AsyncStream, and Combine delivery
offline: no satisfied pathexcellent: latency < 120 msgood: 120–300 msfair: 300–800 mspoor: > 800 ms or frequent probe failures- constrained paths are downgraded
- expensive paths may be downgraded when loss indicates instability
The package includes unit tests for:
- threshold classification behavior
- downgrade rules
- packet-loss rolling-window math
- snapshot state/reducer flow
Run tests:
swift test- adaptive probe intervals based on app foreground/background context
- optional weighted smoothing for latency samples
- richer quality diagnostics for analytics/debug overlays
- additional API conveniences for retry/backoff integration