Contents

harshil-gandhi-us/secondnetwork

Lightweight iOS network reachability listener built on `SystemConfiguration`.

Installation

SPM — add to Package.swift:

.package(url: "https://github.com/harshil-gandhi-us/SecondPod.git", from: "1.0.0")

CocoaPods:

pod 'SecondPod', '~> 1.0'

Usage

import SecondPod

let listener = NetworkListener()
listener.start()

listener.onStatusChange = { status in
    switch status {
    case .connected(let interface): print("Online via \(interface)") // .wifi or .cellular
    case .disconnected:             print("Offline")
    }
}

// Stop when done
listener.stop()

Custom probe host or queue:

let listener = NetworkListener(host: "yourapi.com", queue: .main)

API

| Member | Description | |--------|-------------| | init(host:queue:) | Probe host (default "apple.com"), callback queue (default background). | | start() | Begin observing. Sets currentStatus immediately. | | stop() | Stop observing. | | onStatusChange | Closure called on every change. | | currentStatus | Last known Status. nil before start(). | | isConnected | true when connected. |


See CHANGELOG.md · CODE_OF_CONDUCT.md · LICENSE

Package Metadata

Repository: harshil-gandhi-us/secondnetwork

Default branch: main

README: README.md