Moham Qmaizer
Moham Qmaizer

Reputation: 129

Display UIAlertView when the connection is lost

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

Answers (1)

iDeveloper
iDeveloper

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

Related Questions