Created
January 24, 2017 13:39
-
-
Save TheSwiftyCoder/ef72369229ec185287c015aa0174e1cc to your computer and use it in GitHub Desktop.
Swift 3 Handling user device change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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