iOS - Execute code when application settings are changed

111 Views Asked by At

I am brand new to iOS development and finding it quite difficult to accomplish what I would think to be a fairly simple task.

I have an app that uses Parse push notifications and I would like to subscribe/unsubscribe from channels when the user makes a change to the app's preferences in the Settings application. All of the information that I have found shows how to synchronize settings once the app has been opened again but what I am hoping to accomplish is as follows:

  1. User changes a toggle button for a particular channel in the Settings application - when they toggle it On, I want to subscribe. Off, unsubscribe
  2. When the preference changes, I want to be able to call code in my app to take care of making the change on Parse BEFORE the user opens the app again

The short question - Is there any way to register a callback in the application when a preference is changed in Settings?

Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

There is nothing to "call back". If the user is working in the Settings app, your app, ex hypothesi, is not running.

When your app becomes active once again, you get an event (applicationDidBecomeActive). Your job is to consult your NSUserDefaults to see if anything has changed, as I believe you already know.

If that isn't sufficient, then don't use a Settings bundle - provide subscribe/unsubscribe interface within your app itself.