User is using my app, the goes to System Settings, and changes some of my App's settings (switches, text fields, etc).
Does the system send my app any kind of notification?
David PS: I tried all kinds of searches on this and found nothing.
If you define UserDefaults that cover all the settings you have through System settings of the app and register defaults, that connects UserDefaults to Root.pList.
UserDefaults.standard.register(defaults: defaults)
Define a notification name
extension Notification.Name {
public static let kRefreshPrefs = Notification.Name("refreshPrefs")
}
Then, in AppDelegate, post notification when you enter foreground because you return from System Settings
func applicationWillEnterForeground(_ application: UIApplication) {
NotificationCenter.default.post(name: .kRefreshPrefs, object: self)
}
or do the same in SceneDelegate
func sceneWillEnterForeground(_ scene: UIScene) {
NotificationCenter.default.post(name: .kRefreshPrefs, object: self)
}
In ViewControllers when you need to know setting has changed, add an observer
NotificationCenter.default.addObserver(self, selector: #selector(refreshUserPrefs), name: .kRefreshPrefs, object: nil)
and do what you need to do in the selector