NWReachability - a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

Overview

NWReachability

NWReachability is a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.


  • Latest release: version 1.1.1

  • Requirements: iOS 13.0~ / Swift 5.0~

  • Combine Support

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. To install NWReachability with CocoaPods:

  1. Make sure CocoaPods is installed.

  2. Update your Podfile to include the following:

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '13.0'
    use_frameworks!
    
    target 'YourApp' do
    # your other pod
    # ...
    pod 'NWReachability', '~> 1.1.0'
    end
  3. Run pod install.

  1. In your code import NWReachability like so:
    import NWReachability
    import Combine

Swift Package Manager

  • File > Swift Packages > Add Package Dependency
  • Add https://github.com/aresxin/NWReachability.git
  • Select "Up to Next Major" with "1.1.1"

Usage

Example - notifications

NOTE: All notifications are delivered on the main queue.

let token = NWReachability.default.addObserver { [weak self] connectivity in
 print("connectivity isConnected \(connectivity.isConnected)")
 print("connectivity isExpensive \(connectivity.isExpensive)")
 switch connectivity.status {
 case .reachable(.cellular):
   print("cellular")
 case .notReachable:
   print("notReachable")
 case .reachable(.ethernetOrWiFi):
   print("ethernetOrWiFi")
case .unknown:
   print("unknown")
}
}
NWReachability.default.startMonitoring()

and for stopping notifications

NWReachability.default.stopMonitoring()
NotificationCenter.default.removeObserver(token as Any)

Example - Combine

NWReachability.default.publisher.sink {  [weak self] connectivity in
  print("connectivity isConnected \(connectivity.isConnected)")
  print("connectivity isExpensive \(connectivity.isExpensive)")
  switch connectivity.status {
  case .reachable(.cellular):
    print("cellular")
  case .notReachable:
    print("notReachable")
  case .reachable(.ethernetOrWiFi):
    print("ethernetOrWiFi")
  case .unknown:
    print("unknown")
  }          
}.store(in: &cancellables)
NWReachability.default.startMonitoring()

and for stopping

NWReachability.default.stopMonitoring()
cancellables.removeAll()
You might also like...
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

DispatchSource based socket framework written in pure Swift

SwiftDSSocket Overview SwiftDSSocket is a purely swift based asynchronous socket framework built atop DispatchSource. Function signatures are pretty m

Super lightweight async HTTP server library in pure Swift runs in iOS / MacOS / Linux

Embassy Super lightweight async HTTP server in pure Swift. Please read: Embedded web server for iOS UI testing. See also: Our lightweight web framewor

A resource based, protocol oriented networking library designed for pure-SwiftUI applications.

Monarch 👑 - WIP A resource based, protocol oriented networking library designed for pure-SwiftUI applications. Features: Async/Await Resource Based P

SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN.

SwiftCANLib SwiftCANLib is a library used to process Controller Area Network (CAN) frames utilizing the Linux kernel open source library SOCKETCAN. Th

iOS Network monitor/interceptor framework written in Swift
iOS Network monitor/interceptor framework written in Swift

NetShears NetShears is a Network interceptor framework written in Swift. NetShears adds a Request interceptor mechanisms to be able to modify the HTTP

A remote for your IR devices for iOS and Mac!
A remote for your IR devices for iOS and Mac!

Command your TV, Apple TV or Receiver with your Mac/iOS device through iTach. Screenshots On iOS: On Mac (notification center): How to use Buy a iTach

Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network.

Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network. This approach allows your app to use both network bandwidth and system resources more efficiently. It's built on top of Combine, allowing you to harness its full power, handle errors easily, etc.

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)

SwiftSoup is a pure Swift library, cross-platform (macOS, iOS, tvOS, watchOS and Linux!), for working with real-world HTML. It provides a very conveni

Releases(v1.1.1)
Owner
null
Bonjour networking for discovery and connection between iOS, macOS and tvOS devices.

Merhaba Bonjour networking for discovery and connection between iOS, macOS and tvOS devices. Features Creating Service Start & Stop Service Stop Brows

Abdullah Selek 67 Dec 5, 2022
A simple class to check for internet connection availability in Swift.

Reach A simple class to check for internet connection availability in Swift. Works for both 3G and WiFi connections. Install Manually Add the Reach.sw

Isuru Nanayakkara 459 Dec 29, 2022
iOS app for monitoring and controlling your Tesla vehicles.

Teslawesome This is an unofficial iOS app for monitoring and controling your Tesla vehicles. The purpose of being open sourced is just for more visibi

Ivaylo Gashev 2 Oct 14, 2022
macOS terminal utility for monitoring WiFi link quality

?? wifimon Synopsis wifimon is a wireless device monitoring terminal application that allows you to watch signal, noise and SNR levels as well as devi

Thanos Theodoridis 19 Jun 15, 2022
Shawn Frank 2 Aug 31, 2022
Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.

Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application. Install Carthage

Ronan Rodrigo Nunes 89 Dec 26, 2022
A network extension app to block a user input URI. Meant as a network extension filter proof of concept.

URIBlockNE A network extension app to block a user input URI. Meant as a network extension filter proof of concept. This is just a research effort to

Charles Edge 5 Oct 17, 2022
Say goodbye to the Fat ugly singleton Network Manager with this Network Layer

MHNetwork Protocol Oriented Network Layer Aim to avoid having bloated singleton NetworkManager Philosophy the main philosophy behind MHNetwork is to h

Mohamed Emad Hegab 19 Nov 19, 2022
Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Easy and lightweight network layer for creating different set of network requests like GET, POST, PUT, DELETE customizable with coders conforming to TopLevelDecoder, TopLevelEncoder

Igor 2 Sep 16, 2022
Swift backend / server framework (Pure Swift, Supports Linux)

NetworkObjects NetworkObjects is a #PureSwift backend. This framework compiles for OS X, iOS and Linux and serves as the foundation for building power

Alsey Coleman Miller 258 Oct 6, 2022