The code is still here and you can still clone it, however the library will not receive any more updates or support.
ReachabilityUI is a framework meant to help informing the user when an app loses connection to the internet.
With ReachabilityUI you can even register a ReachabilityListener
instance that will allow you to get notified about the connection drop. This can be used to adjust your application's UI so that the content won't overlap the banner, or for any other action you might need to take when the connectivity drops.
Please refer to the demo project for a showcase on how to integrate the ReachabilityUI framework in a Nodes like VIPER architecture.
- iOS 11
- Swift 4.0+
github "nodes-ios/Reachability-UI"
pod "ReachabilityUI"
Conform to HasReachabilityListenerRepository
and create a ReachabilityUIManager
instance:
import UIKit
import ReachabilityUI
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
public var reachabilityListenerFactory: ReachabilityListenerFactoryProtocol!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
reachabilityListenerFactory = ReachabilityUIManager()
return true
}
}
extension AppDelegate: HasReachabilityListenerRepository {}
To enable the Reachability banner in your views, add the following code snippet to your AppDelegate.swift
:
private func addReachability() {
// create a ReachabilityConfiguration instance
let configuration = ReachabilityConfiguration(title: "Connected",
noConnectionTitle: "No Connection",
options: nil)
// create the ReachabilityCoordinator and pass it along the previously
// created ReachabilityConfiguration together with the ReachabilityListenerFactoryProtocol
let coordinator = ReachabilityCoordinator(
window: window,
reachabilityListenerFactory: reachabilityListenerFactory,
configuration: configuration
)
reachabilityCoordinator = coordinator
coordinator.start()
}
To get notified about connectivity changes you must create a listener
and start listening in order to get notified about the connectivity changes.
private var listener: ReachabilityListenerProtocol!
func subscribe() {
listener = reachabilityListenerFactory.makeListener()
listener.listen { [weak self] (isConnected) in
// TODO: react to change in connected state
}
}
You can change the various options in the ReachabilityConfiguration
to tailor the component to your needs.
let configuration = ReachabilityConfiguration(title: "Connected",
noConnectionTitle: "No Connection",
options: [.appearance : ReachabilityConfiguration.Appearance.bottom,
.appearanceAdjustment : CGFloat(-100),
.animation : ReachabilityConfiguration.Animation.slideAndFadeInOutFromBottom])
The following keys can be used in the options
dictionary:
.titleColor
(must be aUIColor
).noConnectionTitleColor
(must be aUIColor
).noConnectionBackgroundColor
(must be aUIColor
).backgroundColor
(must be aUIColor
).height
(must be aCGFloat
).font
(must be aUIFont
).textAlignment
(must be aNSTextAlignment
).animation
(must be aReachabilityConfiguration.Animation
).appearance
(must be aReachabilityConfiguration.Appearance
).appearanceAdjustment
(must be aCGFloat
)
If options are set to nil
, default options will be used. Any options set, will override the default state.
Made with ❤️ at Nodes.
Reachability logic is as presented by Marco Santarossa on https://medium.com/@marcosantadev/network-reachability-with-swift-576ca5070e4b
Reachability-UI is available under the MIT license. See the LICENSE file for more info.