Detecting Internet Access on iOS 12+

If the framework property is set to network then the new Network framework will be used in place of theSystemConfigurationframework (Reachability) for observing state changes in network adapters.let connectivity = Connectivity()connectivity.framework = .networkFollowing a state change in a network adapter, Connectivity performs a number of checks to determine whether Internet access is available..A polling option is available which can be used to revalidate whether Internet access is available every so often even where a state change has not occurred — should this be required..This can be achieved by setting isPollingEnabled = trueand specifying an appropriate value in seconds for the pollingInterval.SummaryThe Network framework introduces some great new classes including NWPathMonitor which can be used to observe state changes in a device’s network adapters on iOS 12 and above..It reports a path as satisfied after a captive portal has been interacted with by the user but doesn’t detect the subsequent loss of Internet access..Connectivity can be used to provide backwards compatibility for apps supporting previous versions of iOS and greater accuracy over using NWPathMonitor alone.AdvantagesOfficially supported by Apple.No need to include third party code — simply link Network.framework in iOS 12.Reports an NWPath’s Status as being satisfied after having negotiated the captive portal.DisadvantagesCannot be used prior to iOS 12 which means that if you need to support earlier versions of iOS you’re out of luck.Lack of documentation — take a look at https://developer.apple.com/documentation/network/nwpathmonitor for example.Doesn’t detect captive portals and other situations where Internet connectivity drops out following an initial successful connection.Connectivity can be found open-sourced on GitHub under MIT license and is compatible with both Cocoapods and Carthage.. More details

Leave a Reply