Skip to content

Instantly share code, notes, and snippets.

@paulw11
Created May 15, 2020 22:40
Show Gist options
  • Save paulw11/0d08de1e8477b9fab09096130bb63492 to your computer and use it in GitHub Desktop.
Save paulw11/0d08de1e8477b9fab09096130bb63492 to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// NWPathMonitor
//
// Created by Paul Wilkinson on 16/5/20.
// Copyright © 2020 Paul Wilkinson. All rights reserved.
//
import UIKit
import Network
class ViewController: UIViewController {
@IBOutlet weak var stateLabel: UILabel!
let pathMonitor = NWPathMonitor()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.pathMonitor.pathUpdateHandler = { path in
DispatchQueue.main.async {
switch path.status {
case .requiresConnection:
self.stateLabel.text = "Requires connection"
case .satisfied:
self.stateLabel.text = "Satisfied"
case .unsatisfied:
self.stateLabel.text = "Unsatisfied"
}
}
}
self.pathMonitor.start(queue: DispatchQueue.global())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment