提交 4b14a977 编写于 作者: C Christian Noon

Added reachability monitoring to the console for the sample app

上级 4711de71
......@@ -27,6 +27,8 @@ import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
// MARK: - Properties
var window: UIWindow?
// MARK: - UIApplicationDelegate
......
......@@ -27,32 +27,24 @@ import UIKit
class MasterViewController: UITableViewController {
// MARK: - Properties
@IBOutlet weak var titleImageView: UIImageView!
var detailViewController: DetailViewController? = nil
var objects = NSMutableArray()
private var reachability: NetworkReachabilityManager!
// MARK: - View Lifecycle
override func awakeFromNib() {
super.awakeFromNib()
navigationItem.titleView = titleImageView
}
override func viewDidLoad() {
super.viewDidLoad()
if let split = splitViewController {
let controllers = split.viewControllers
clearsSelectionOnViewWillAppear = true
if
let navigationController = controllers.last as? UINavigationController,
let topViewController = navigationController.topViewController as? DetailViewController
{
detailViewController = topViewController
}
}
monitorReachability()
}
// MARK: - UIStoryboardSegue
......@@ -93,5 +85,25 @@ class MasterViewController: UITableViewController {
}
}
}
}
// MARK: - UITableViewDelegate
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 3 && indexPath.row == 0 {
print("Reachability Status: \(reachability.networkReachabilityStatus)")
tableView.deselectRow(at: indexPath, animated: true)
}
}
// MARK: - Private - Reachability
private func monitorReachability() {
reachability = NetworkReachabilityManager(host: "www.apple.com")
reachability.listener = { status in
print("Reachability Status Changed: \(status)")
}
reachability.startListening()
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册