All Projects → RxSwiftCommunity → Rxreachability

RxSwiftCommunity / Rxreachability

Licence: mit
RxSwift bindings for Reachability

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Rxreachability

Tiercel
简单易用、功能丰富的纯 Swift 下载框架
Stars: ✭ 2,241 (+1138.12%)
Mutual labels:  network
Vieb
Vim Inspired Electron Browser - Vim bindings for the web by design
Stars: ✭ 175 (-3.31%)
Mutual labels:  network
Reactorkit
A library for reactive and unidirectional Swift applications
Stars: ✭ 2,237 (+1135.91%)
Mutual labels:  rxswift
Medium
Independent telecommunication environment
Stars: ✭ 171 (-5.52%)
Mutual labels:  network
Marmot
Marmot workflow execution engine
Stars: ✭ 174 (-3.87%)
Mutual labels:  network
Rxgrdb
Reactive extensions for SQLite
Stars: ✭ 176 (-2.76%)
Mutual labels:  rxswift
React Native Zeroconf
📡 Discover Zeroconf services using react-native
Stars: ✭ 168 (-7.18%)
Mutual labels:  network
Txeh
Go library and CLI utilty for /etc/hosts management.
Stars: ✭ 181 (+0%)
Mutual labels:  network
Rxiglistkit
IGListKit with RxSwift🚀
Stars: ✭ 174 (-3.87%)
Mutual labels:  rxswift
Grab
Web Scraping Framework
Stars: ✭ 2,147 (+1086.19%)
Mutual labels:  network
Github.swift
Unofficial GitHub API client in Swift
Stars: ✭ 171 (-5.52%)
Mutual labels:  rxswift
Netdev
Asynchronous multi-vendor library for interacting with network devices
Stars: ✭ 172 (-4.97%)
Mutual labels:  network
Rxwebkit
RxWebKit is a RxSwift wrapper for WebKit
Stars: ✭ 176 (-2.76%)
Mutual labels:  rxswift
Swifthub
GitHub iOS client in RxSwift and MVVM-C clean architecture
Stars: ✭ 2,330 (+1187.29%)
Mutual labels:  rxswift
Modernavplayer
ModernAVPlayer is a persistence AVPlayer wrapper
Stars: ✭ 179 (-1.1%)
Mutual labels:  rxswift
Ns3 Mmwave
ns-3 module for simulating mmWave-based cellular systems. See https://ieeexplore.ieee.org/document/8344116/ (open access) as a reference.
Stars: ✭ 169 (-6.63%)
Mutual labels:  network
Ivre
Network recon framework, published by @cea-sec & @ANSSI-FR. Build your own, self-hosted and fully-controlled alternatives to Shodan / ZoomEye / Censys and GreyNoise, run your Passive DNS service, collect and analyse network intelligence from your sensors, and much more!
Stars: ✭ 2,331 (+1187.85%)
Mutual labels:  network
Piano Rs
A multiplayer piano using UDP sockets that can be played using computer keyboard, in the terminal
Stars: ✭ 180 (-0.55%)
Mutual labels:  network
Hxphotopicker
图片/视频选择器 - 支持LivePhoto、GIF图片选择、3DTouch预览、在线下载iCloud上的资源、编辑图片/视频、浏览网络图片 功能 Imitation wx photo/image picker - support for LivePhoto, GIF image selection, 3DTouch preview, Download the resources on iCloud online, browse the web image function
Stars: ✭ 2,363 (+1205.52%)
Mutual labels:  network
100 Days Of Rxswift
💨100 days and 40 project of RxSwift
Stars: ✭ 177 (-2.21%)
Mutual labels:  rxswift

Logo

RxReachability

GitHub release Version License Platform Build Status

RxReachability adds easy to use RxSwift bindings for ReachabilitySwift. You can react to network reachability changes and even retry observables when network comes back up.

Available APIs

RxReachability adds the following RxSwift bindings:

  • reachabilityChanged: Observable<Reachability>
  • status: Observable<Reachability.NetworkStatus>
  • isReachable: Observable<Bool>
  • isConnected: Observable<Void>
  • isDisconnected: Observable<Void>

Common Usage

1. Be sure to store an instance of Reachability in your ViewController or similar, and start/stop the notifier on viewWillAppear and viewWillDisappear methods.

class ViewController: UIViewController {

  let disposeBag = DisposeBag()
  var reachability: Reachability?

  override func viewDidLoad() {
    super.viewDidLoad()
    reachability = Reachability()
  }

  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    try? reachability?.startNotifier()
  }

  override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    reachability?.stopNotifier()
  }
}

2. Subscribe to any of the bindings to know when a change happens.

extension ViewController {

  let disposeBag = DisposeBag()

  func bindReachability() {

    reachability?.rx.reachabilityChanged
      .subscribe(onNext: { reachability: Reachability in
        print("Reachability changed: \(reachability.currentReachabilityStatus)")
      })
      .disposed(by: disposeBag)

    reachability?.rx.status
      .subscribe(onNext: { status: Reachability.NetworkStatus in
        print("Reachability status changed: \(status)")
      })
      .disposed(by: disposeBag)

    reachability?.rx.isReachable
      .subscribe(onNext: { isReachable: Bool in
        print("Is reachable: \(isReachable)")
      })
      .disposed(by: disposeBag)

    reachability?.rx.isConnected
      .subscribe(onNext: {
        print("Is connected")
      })
      .disposed(by: disposeBag)

    reachability?.rx.isDisconnected
      .subscribe(onNext: {
        print("Is disconnected")
      })
      .disposed(by: disposeBag)
  }

Static Usage

1. Be sure to store an instance of Reachability somewhere on your AppDelegate or similar, and start the notifier.

import Reachability

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var reachability: Reachability?

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    reachability = Reachability()
    try? reachability?.startNotifier()
    return true
  }
}

2. Subscribe to any of the bindings to know when a change happens.

import Reachability
import RxReachability
import RxSwift

class ViewController: UIViewController {

  let disposeBag = DisposeBag()

  override func viewDidLoad() {
    super.viewDidLoad()

    Reachability.rx.reachabilityChanged
      .subscribe(onNext: { reachability: Reachability in
        print("Reachability changed: \(reachability.currrentReachabilityStatus)")
      })
      .disposed(by: disposeBag)

    Reachability.rx.status
      .subscribe(onNext: { status: Reachability.NetworkStatus in
        print("Reachability status changed: \(status)")
      })
      .disposed(by: disposeBag)

    Reachability.rx.isReachable
      .subscribe(onNext: { isReachable: Bool in
        print("Is reachable: \(isReachable)")
      })
      .disposed(by: disposeBag)

    Reachability.rx.isConnected
      .subscribe(onNext: {
        print("Is connected")
      })
      .disposed(by: disposeBag)

    Reachability.rx.isDisconnected
      .subscribe(onNext: {
        print("Is disconnected")
      })
      .disposed(by: disposeBag)
  }

Advanced Usage

With RxReachability you can also add a retry when network comes back up with a given timeout. This does require you to have a stored instance of Reachability though.

func request(somethingId: Int) -> Observable<Something> {
  return network.request(.something(somethingId))
    .retryOnConnect(timeout: 30)
    .map { Something(JSON: $0) }
}

Installation

Installation via CocoaPods

To integrate RxReachability into your Xcode project using CocoaPods, simply add the following line to your Podfile:

pod 'RxReachability'

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

License

This library belongs to RxSwiftCommunity.

RxReachability is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].