Advertisement
Guest User

Untitled

a guest
Oct 11th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.81 KB | None | 0 0
  1. func monitorReachabilityChanges(reach: (reachabilityStatus: ReachabilityStatus) -> ()) {
  2.     let host = "google.com"
  3.     var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil)
  4.     let reachability = SCNetworkReachabilityCreateWithName(nil, host)!
  5.    
  6.     SCNetworkReachabilitySetCallback(reachability, { (_, flags, _) in
  7.         let status = ReachabilityStatus(reachabilityFlags: flags)
  8.        
  9.         // NSNotificationCenter.defaultCenter().postNotificationName(ReachabilityStatusChangedNotification, object: nil, userInfo: ["Status": status.description])
  10.        
  11.         reach(reachabilityStatus: status)
  12.        
  13.     }, &context)
  14.    
  15.    
  16.    
  17.     SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes)
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement