Created
May 15, 2020 22:40
-
-
Save paulw11/0d08de1e8477b9fab09096130bb63492 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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