NetReachability用于检查网络连接的连通性。
private lazy var reachability: NetReachability = NetReachability(hostname: "www.baidu.com") //添加通知 NSNotificationCenter.defaultCenter().addObserver(self, selector: "statusChanged", name: FFReachabilityChangedNotification, object: nil) reachability.startNotifier() //移除通知 reachability.stopNotifier() NSNotificationCenter.defaultCenter().removeObserver(self, name: FFReachabilityChangedNotification, object: nil) //观察者 func statusChanged() { print(reachability.currentReachabilityStatus) }