Connectivity
π Makes Internet connectivity detection more robust by detecting Wi-Fi networks without Internet access.
Install / Use
/learn @rwbutler/ConnectivityREADME

Swift concurrency support coming shortly.
Connectivity is a wrapper for Apple's Reachability providing a reliable measure of whether Internet connectivity is available where Reachability alone can only indicate whether an interface is available that might allow a connection.
Connectivity's objective is to solve the captive portal problem whereby an iOS device is connected to a WiFi network lacking Internet connectivity. Such situations are commonplace and may occur for example when connecting to a public WiFi network which requires the user to register before use. Connectivity can detect such situations enabling you to react accordingly.
To learn more about how to use Connectivity, take a look at the keynote presentation, check out the blog post, or make use of the table of contents below:
- Features
- Hyperconnectivity
- Installation
- How It Works
- Usage
- Known Issues
- Author
- License
- Additional Software
Features
- [x] Detect captive portals when a device joins a network.
- [x] Detect when connected to a router that has no Internet access.
- [x] Be notified of changes in Internet connectivity.
- [x] Polling connectivity checks may be performed where a constant network connection is required (optional).
- [x] Combine support via
Connectivity.Publisher.
What's new in Connectivity 8.0.0?
For more information, see CHANGELOG.md.
Hyperconnectivity
If you don't require support for Objective-C or versions of iOS prior to iOS 13 then you may want to consider using Hyperconnectivity (an offshoot project of Connectivity), which drops support for these in favour of a modern, elegant syntax. For a comparison of the two frameworks see here.
<br/> <div align="center"> <a href="https://github.com/rwbutler/Hyperconnectivity"><img src="https://github.com/rwbutler/Hyperconnectivity/raw/master/docs/images/hyperconnectivity-logo.png" alt="Hyperconnectivity logo" height="100" width="100"></a> </div>OpenConnectivity
Connectivity and Hyperconnectivity both provide support for Combine however if you're working in an environment where Combine is unavailable e.g. supporting versions of iOS prior to 13 then you may make use of OpenCombine.
OpenConnectivity extends Connectivity with an OpenCombine-compatible publisher to allow you to take advantage of Combine syntax in environments where Combine itself is unavailable.
Installation
Ensure that you include Apple's Reachability header and implementation files (Reachability.h and Reachability.m) to use.
Use of Apple's Reachability is subject to licensing from Apple.
Cocoapods
CocoaPods is a dependency manager which integrates dependencies into your Xcode workspace. To install it using Ruby gems run:
gem install cocoapods
To install Connectivity using Cocoapods, simply add the following line to your Podfile:
pod "Connectivity"
Then run the command:
pod install
For more information see here.
Carthage
Carthage is a dependency manager which produces a binary for manual integration into your project. It can be installed via Homebrew using the commands:
brew update
brew install carthage
In order to integrate Connectivity into your project via Carthage, add the following line to your project's Cartfile:
github "rwbutler/Connectivity"
From the macOS Terminal run carthage update --platform iOS to build the framework then drag Connectivity.framework into your Xcode project.
For more information see here.
Swift Package Manager
Xcode (11 and above) includes support for Swift Package Manager. In order to add Connectivity to your Xcode project, from the File menu select Swift Packages and then select Add Package Dependency.
A dialogue will request the package repository URL which is:
https://github.com/rwbutler/connectivity
After verifying the URL, Xcode will prompt you to select whether to pull a specific branch, commit or versioned release into your project.
<div align="center"> <img src="https://github.com/rwbutler/Connectivity/raw/main/docs/images/package-options.png" alt="Xcode 11 Package Options" width="80%"> </div>Proceed to the next step by where you will be asked to select the package product to integrate into a target. There will be a single package product named Connectivity which should be pre-selected. Ensure that your main app target is selected from the rightmost column of the dialog then click Finish to complete the integration.
How It Works
iOS adopts a protocol called Wireless Internet Service Provider roaming (WISPr 2.0) published by the Wireless Broadband Alliance. This protocol defines the Smart Client to Access Gateway interface describing how to authenticate users accessing public IEEE 802.11 (Wi-Fi) networks using the Universal Access Method in which a captive portal presents a login page to the user.
The user must then register or provide login credentials via a web browser in order to be granted access to the network using RADIUS or another protocol providing centralized Authentication, Authorization, and Accounting (AAA).
In order to detect a that it has connected to a Wi-Fi network with a captive portal, iOS contacts a number of endpoints hosted by Apple - an example being https://www.apple.com/library/test/success.html. Each endpoint hosts a small HTML page of the form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Success</TITLE>
</HEAD>
<BODY>
Success
</BODY>
</HTML>
If on downloading this small HTML page iOS finds that it contains the word Success as above then it knows that Internet connectivity is available. However, if a login page is presented by a captive portal then the word Success will not be present and iOS will realize that the network connection has been hijacked by a captive portal and will present a browser window allowing the user to login or register.
Apple hosts a number of these pages such that should one of these pages go down, a number of fallbacks can be checked to determine whether connectivity is present or whether our connection is blocked by the presence of a captive portal. Unfortunately iOS exposes no framework to developers which allows us to make use of the operating systemβs awareness of captive portals.
Connectivity is an open-source framework which wraps Reachability and endeavours to replicate iOSβs me
