SSASwiftReachability监控网络连接
SSASwiftReachability 是用来监控网络可连接能力变化的 Swift 库。
使用:
override func viewDidLoad() { super.viewDidLoad() // MARK: Start Monitoring For Network Reachability Changes. SSASwiftReachability.sharedManager?.startMonitoring() // MARK: Listen For Network Reachability Changes NSNotificationCenter.defaultCenter().addObserver(self, selector: "reachabilityStatusChanged:", name: reachabilityDidChangeNotification, object: nil) } func reachabilityStatusChanged(notification: NSNotification) { if let info = notification.userInfo { if let s = info[reachabilityNotificationStatusItem] { print(s.description) } } }
评论