Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. let reachability = Reachability.reachabilityForInternetConnection()
  2.  
  3. reachability!.whenReachable = { reachability in
  4.  
  5. if reachability.isReachableViaWiFi() {
  6.  
  7. let alertController = UIAlertController(title: "Alert", message: "Reachable via WiFi", preferredStyle: .Alert)
  8.  
  9.  
  10.  
  11. let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
  12.  
  13. alertController.addAction(defaultAction)
  14.  
  15.  
  16.  
  17. self.presentViewController(alertController, animated: true, completion: nil)
  18.  
  19.  
  20.  
  21. }
  22.  
  23. else {
  24.  
  25. let alertController = UIAlertController(title: "Alert", message: "Reachable via Cellular", preferredStyle: .Alert)
  26.  
  27.  
  28.  
  29. let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
  30.  
  31. alertController.addAction(defaultAction)
  32.  
  33.  
  34.  
  35. self.presentViewController(alertController, animated: true, completion: nil)
  36.  
  37. }
  38.  
  39. }
  40.  
  41. reachability!.whenUnreachable = { reachability in
  42.  
  43. let alertController = UIAlertController(title: "Alert", message: "Please connect to internet", preferredStyle: .Alert)
  44.  
  45.  
  46.  
  47. let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
  48.  
  49. alertController.addAction(defaultAction)
  50.  
  51.  
  52.  
  53. self.presentViewController(alertController, animated: true, completion: nil)
  54.  
  55. }
  56.  
  57.  
  58.  
  59. reachability!.startNotifier()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement