User changes Settings for my app, any notification?

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.

Answered by Claude31 in 838520022

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

We appreciate your interest in participating in the forums! These forums are for questions about developing software and accessories for Apple platforms. Your question seems related to a consumer feature and is better suited for the Apple Support Communities

https://discussions.apple.com/welcome

Albert Pascual
  Worldwide Developer Relations.

Accepted Answer

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

User changes Settings for my app, any notification?
 
 
Q