Swiftpack.co - agnosticdev/NetworkConnectivity as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by agnosticdev.
agnosticdev/NetworkConnectivity 1.0.0
Swift Package designed as an alternative to detecting network connectivity when traditional methods do not work. Designed for iOS and macOS
⭐️ 10
🕓 5 years ago
.package(url: "https://github.com/agnosticdev/NetworkConnectivity.git", from: "1.0.0")

NetworkConnectivity

Swift Package designed as an alternative to detecting network connectivity when traditional methods do not work. For example, Apple recommends that to properly check connectivity your application should send a network request and the request should let your application know the connectivity state of the device. If device is offline the request should fail immediately and you can provide the user with proper feedback. If the device is online the request will go out and you can also inform your user that the application is waiting for updated data.

In most cases this approach works great. There are some rare conditions that still exist that require your application to still check for the connectivity state of the device. For these rare cases the NetworkConnectivity package was built. NetworkConnectivity examines the state of a TCP connection and provides updates to a delegate method so your application can act accordingly.

class BaseViewController: ViewController {
    func viewDidLoad() {
        let _ = NetworkConnectivity.shared.setup(with: "agnosticdev.com")
    }
 }
 
extension BaseViewController: NetworkConnectivityDelegate {
    
    public func networkStatusChanged(online: Bool, connectivityStatus: String) {
        if online { 
            // handle online status
        } else {
            // handle offline status
        }
    }
}

GitHub

link
Stars: 10
Last commit: 5 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics