Reputation: 129
What is the best way to display an alert in any view in my app when the connection is lost.
Currently using:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.networkStatusChanged(_:)), name: ReachabilityStatusChangedNotification, object: nil)
Reach().monitorReachabilityChanges()
func networkStatusChanged(notification: NSNotification) {
if let info = notification.userInfo as? [String:String] {
let status = info["Status"]!
if !status.containsString("Online") {
}
}
}
Upvotes: 1
Views: 106
Reputation: 150
UIAlertViews have been deprecated, use UIAlertController instead.
let alert = UIAlertController(title: "Error", message: "You you seem to have lost internet connectivity.", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: .Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
Upvotes: 3