A simple Swift package to monitor network connectivity using NWPathMonitor
.
✅ Detects real-time network connectivity changes.
✅ Supports Wi-Fi, Cellular, Ethernet, and Loopback interfaces.
✅ Provides details like IPv4/IPv6 support and DNS availability.
✅ Uses AsyncStream
for easy async monitoring.
- Open Xcode, go to File → Add Packages.
- Enter the repository URL: https://github.com/Rohijulislam/NetworkMonitorKit.git
- Select Add Package and import it into your project:
import NetworkMonitorKit
let networkMonitor = NetworkMonitorKit()
networkMonitor.startMonitoring()
if networkMonitor.isNetworkAvailable {
print("✅ Network is available")
} else {
print("❌ No network connection")
}
let details = networkMonitor.connectionDetails
print("Interface Type: \(details.interfaceType)")
print("Supports IPv4: \(details.supportsIPv4)")
print("Supports IPv6: \(details.supportsIPv6)")
Task {
for await status in networkMonitor.monitorNetworkStatus() {
print("🔄 Network status changed: \(status)")
}
}
This package is released under the MIT License.