0

I want my app to be able to let me know whenever internet connection is lost during my app, via a red notification/status banner on top, using the popular library Reachability (not Apple's native).

An example of what I want to achieve is something like in Pokemon GO. https://imgur.com/T29rJKV

I only got this code which kinda works, but doesn't detect when wi-fi is back on.

class ViewController: UIViewController {

let reachability = try! Reachability()

override func viewDidLoad() {
    super.viewDidLoad()

    //Does not work when internet connection is offline, then comes back online
    reachability.whenReachable = { _ in
          print("Reachable")
      }

      reachability.whenUnreachable = { _ in
          print("Not reachable")
      }

    //Don't know what notifier is, seems to fire off above closures
    do {
        try reachability.startNotifier()
    } catch {
        print("Unable to start notifier")
    }

}

How do I use the Reachability library to asynchronously loop/constantly check if there's an issue with internet connection? How do I create a similar status bar on my tab controller, so that all views in my app's flow creates this red status bar whenever there's an issue with internet?

  • Why don't you download the latest Reachability project? The sample does exactly what you are trying to achieve. – Leo Dabus May 29 '20 at 02:46

0 Answers0