Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. func listenForFirebaseConnection(callback: @escaping () -> Void) {
  2. FireDataUtil().getBase().child(".info/connected").observeSingleEvent(of: .value, with: { (snapshot) in
  3. if snapshot.exists() {
  4. let isConnected = snapshot.value as! Bool?
  5. if isConnected != nil && isConnected == false {
  6.  
  7. let view = MessageView.viewFromNib(layout: .MessageView)
  8. view.button?.isHidden = false
  9.  
  10. // Theme message elements with the warning style.
  11. view.configureTheme(.error)
  12.  
  13. // Add a drop shadow.
  14. view.configureDropShadow()
  15.  
  16. // Set message title, body, and icon. Here, we're overriding the default warning
  17. // image with an emoji character.
  18. view.configureContent(title: "Network Issue", body: "It looks like your network connection is either slow or disconnected")
  19. view.button?.setTitle("Reload", for: .normal)
  20.  
  21. view.button?.addTarget(self, action: #selector(callback), for: .touchUpInside)
  22. var config = SwiftMessages.Config()
  23.  
  24. config.presentationContext = .window(windowLevel: UIWindowLevelStatusBar)
  25. config.presentationStyle = .bottom
  26. config.duration = .seconds(seconds: 5)
  27.  
  28. // Show the message.
  29. SwiftMessages.show(config: config, view: view)
  30. }
  31. }
  32. })
  33. }
  34.  
  35. #selector(ViewController.callback)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement