2

Is there any way that using the NSUserDefaultsDidChangeNotification I can be notified of changes made to the general device settings?

I am not sure what settings are being referred to here. Does it talk only about the app specific settings or the overall device settings.

What I want to do exactly is this: I want a notification if the user turns on/off the wifi or bluetooth or any other setting for that matter. Is it possible that I can do that using NSUserDefaultsDidChangeNotification??

As of now what I could think of was to create a custom notification which is fired everytime a variable's value is changed. however, I will have to continuously poll for the setting's value in that case.

megZo
  • 734
  • 6
  • 19

1 Answers1

0

From the NSUserDefaults class reference:

The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its behavior to match a user’s preferences. For example, you can allow users to determine what units of measurement your application displays or how often documents are automatically saved. Applications record such preferences by assigning values to a set of parameters in a user’s defaults database. The parameters are referred to as defaults since they’re commonly used to determine an application’s default state at startup or the way it acts by default.

Based on what you want to do which is to monitor wifi or bluetooth or other device settings, it is not possible to use NSUserDefaults for this purpose. So yeah, you can't use NSUserDefaultsDidChangeNotification. it is more for the user default settings for your particular app.

How to determine wifi: iPhone Wifi on or off?

For Bluetooth availability, I think you can use Core Bluetooth. For other device settings, you will need to look for it one by one.

Community
  • 1
  • 1
Valent Richie
  • 5,226
  • 1
  • 20
  • 21
  • Hey thanks! Your conclusion that I cant use NSUserDefaults for my purpose, helps. I have already managed to do this for wifi and bluetooth using the reachability and core bluetooth API. I was just hoping to get a lead to some other settings using the NSUserDefaults class as I cant seem to be able to read them any other way.. – megZo Jun 01 '13 at 19:18
  • 1
    @meghna NSUserDefaults is for storing your own app preferences, not for reading device-wide settings :) – Valent Richie Jun 02 '13 at 10:36