Skip to content

Instantly share code, notes, and snippets.

@TheSwiftyCoder
Created January 24, 2017 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSwiftyCoder/ef72369229ec185287c015aa0174e1cc to your computer and use it in GitHub Desktop.
Save TheSwiftyCoder/ef72369229ec185287c015aa0174e1cc to your computer and use it in GitHub Desktop.
Swift 3 Handling user device change
// Creates the notifcation constant
let notification = Notification.Name("NSSystemClockDidChangeNotification")
// Add this within your viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(handleTimeChange), name: notification, object: nil)
// Place this within the view controller where the above is added
@objc private func handleTimeChange() {
// Add anything you need in here
NotificationCenter.default.removeObserver(self, name: notification, object: nil);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment