Multiple applications, one NSUserDefaults object?

  • I've got a project going with a preference pane and a background
    application that both need to access the user defaults for the same
    domain. Currently I have the preference pane using [NSUserDefaults
    standardUserDefaults], and the app using CFPreferencesCopyAppValue and
    CFPreferencesSetAppValue with the prefPane's appID. Is there a way to
    get an NSUserDefaults instance in the app that modifies the domain of
    the preference pane, or am I stuck with the CF stuff?
  • On 2007 Nov, 25, at 21:13, Jacob Bandes-Storch wrote:

    > I've got a project going with a preference pane and a background
    > application that both need to access the user defaults for the same
    > domain. Currently I have the preference pane using [NSUserDefaults
    > standardUserDefaults], and the app using CFPreferencesCopyAppValue
    > and CFPreferencesSetAppValue with the prefPane's appID. Is there a
    > way to get an NSUserDefaults instance in the app that modifies the
    > domain of the preference pane, or am I stuck with the CF stuff?

    Cheap and simple: I set the CFBundleIdentifier in my background
    helper's Info.plist to be the same as the main app, and then
    [NSUserDefaults standardUserDefaults] "just works".

    (Although my main app is an app; I've never done a preference pane.)
  • Or you can use:

    - (void)addSuiteNamed:(NSString *)suiteName

    of The NSUserDefaults class in your main app. If you chose the Bundle-
    Identifier of your preferences App, all the keys will be also
    available to your main app.

    -
    Joachim

    Am 26.11.2007 um 06:49 schrieb Jerry Krinock:

    >
    > On 2007 Nov, 25, at 21:13, Jacob Bandes-Storch wrote:
    >
    >> I've got a project going with a preference pane and a background
    >> application that both need to access the user defaults for the same
    >> domain. Currently I have the preference pane using [NSUserDefaults
    >> standardUserDefaults], and the app using CFPreferencesCopyAppValue
    >> and CFPreferencesSetAppValue with the prefPane's appID. Is there a
    >> way to get an NSUserDefaults instance in the app that modifies the
    >> domain of the preference pane, or am I stuck with the CF stuff?
    >
    > Cheap and simple: I set the CFBundleIdentifier in my background
    > helper's Info.plist to be the same as the main app, and then
    > [NSUserDefaults standardUserDefaults] "just works".
    >
    > (Although my main app is an app; I've never done a preference pane.)
  • Am 26.11.2007 um 06:49 schrieb Jerry Krinock:
    > On 2007 Nov, 25, at 21:13, Jacob Bandes-Storch wrote:
    >> I've got a project going with a preference pane and a background
    >> application that both need to access the user defaults for the same
    >> domain. Currently I have the preference pane using [NSUserDefaults
    >> standardUserDefaults], and the app using CFPreferencesCopyAppValue
    >> and CFPreferencesSetAppValue with the prefPane's appID. Is there a
    >> way to get an NSUserDefaults instance in the app that modifies the
    >> domain of the preference pane, or am I stuck with the CF stuff?
    >
    > Cheap and simple: I set the CFBundleIdentifier in my background
    > helper's Info.plist to be the same as the main app, and then
    > [NSUserDefaults standardUserDefaults] "just works".
    >
    > (Although my main app is an app; I've never done a preference pane.)

      That's dangerous, though. Launch Services may get confused over
    which Info.plist is authoritative, and may only load one of them, now,
    or in the future if Apple chooses to optimize something. You shouldn't
    have two distinct bundles with the same bundle ID.

    Cheers,
    -- M. Uli Kusterer
    "The Witnesses of TeachText are everywhere..."
    http://www.zathras.de
  • Aren't the CFBundleIDs of bundles supposed to be unique? Will I run
    into problems there, or can I just go ahead and give them the same ID?
    Otherwise, I'll try addSuiteNamed:.

    > Or you can use:
    >
    > - (void)addSuiteNamed:(NSString *)suiteName
    >
    > of The NSUserDefaults class in your main app. If you chose the Bundle-
    > Identifier of your preferences App, all the keys will be also
    > available to your main app.
    >
    > -
    > Joachim
    >
    > Am 26.11.2007 um 06:49 schrieb Jerry Krinock:
    >
    >>
    >> On 2007 Nov, 25, at 21:13, Jacob Bandes-Storch wrote:
    >>
    >>> I've got a project going with a preference pane and a background
    >>> application that both need to access the user defaults for the same
    >>> domain. Currently I have the preference pane using [NSUserDefaults
    >>> standardUserDefaults], and the app using CFPreferencesCopyAppValue
    >>> and CFPreferencesSetAppValue with the prefPane's appID. Is there a
    >>> way to get an NSUserDefaults instance in the app that modifies the
    >>> domain of the preference pane, or am I stuck with the CF stuff?
    >>
    >> Cheap and simple: I set the CFBundleIdentifier in my background
    >> helper's Info.plist to be the same as the main app, and then
    >> [NSUserDefaults standardUserDefaults] "just works".
    >>
    >> (Although my main app is an app; I've never done a preference pane.)
  • For me the it's working without problems. I have a background App and
    another standalone App for setting the preferences. In the Background
    App, I'm just using addSuiteNamed and all the keys that were set by my
    standalone App are available.

    -
    Joachim

    Am 26.11.2007 um 15:49 schrieb Jacob Bandes-Storch:

    > Aren't the CFBundleIDs of bundles supposed to be unique? Will I run
    > into problems there, or can I just go ahead and give them the same
    > ID? Otherwise, I'll try addSuiteNamed:.
    >
    >> Or you can use:
    >>
    >> - (void)addSuiteNamed:(NSString *)suiteName
    >>
    >> of The NSUserDefaults class in your main app. If you chose the
    >> Bundle-
    >> Identifier of your preferences App, all the keys will be also
    >> available to your main app.
    >>
    >> -
    >> Joachim
    >>
    >> Am 26.11.2007 um 06:49 schrieb Jerry Krinock:
    >>
    >>>
    >>> On 2007 Nov, 25, at 21:13, Jacob Bandes-Storch wrote:
    >>>
    >>>> I've got a project going with a preference pane and a background
    >>>> application that both need to access the user defaults for the same
    >>>> domain. Currently I have the preference pane using [NSUserDefaults
    >>>> standardUserDefaults], and the app using CFPreferencesCopyAppValue
    >>>> and CFPreferencesSetAppValue with the prefPane's appID. Is there a
    >>>> way to get an NSUserDefaults instance in the app that modifies the
    >>>> domain of the preference pane, or am I stuck with the CF stuff?
    >>>
    >>> Cheap and simple: I set the CFBundleIdentifier in my background
    >>> helper's Info.plist to be the same as the main app, and then
    >>> [NSUserDefaults standardUserDefaults] "just works".
    >>>
    >>> (Although my main app is an app; I've never done a preference pane.)
  • On 2007 Nov, 26, at 9:32, Joachim Deelen wrote:

    > For me the it's working without problems. I have a background App
    > and another standalone App for setting the preferences. In the
    > Background App, I'm just using addSuiteNamed and all the keys that
    > were set by my standalone App are available.

    OK, so I changed my background app to have a different bundle
    identifier than my main app, added addSuiteNamed: and indeed it works.

    But of course this only works for reading preferences.  My background
    app also writes a preference.  (Some simple and cheap interapplication
    communication.)  To restore that facility, I called upon
    CFPreferencesSetAppValue() and CFPreferencesSynchronize().
  • >
    > On 2007 Nov, 26, at 9:32, Joachim Deelen wrote:
    >
    >> For me the it's working without problems. I have a background App
    >> and another standalone App for setting the preferences. In the
    >> Background App, I'm just using addSuiteNamed and all the keys that
    >> were set by my standalone App are available.
    >
    > OK, so I changed my background app to have a different bundle
    > identifier than my main app, added addSuiteNamed: and indeed it works.
    >
    > But of course this only works for reading preferences.  My background
    > app also writes a preference.  (Some simple and cheap interapplication
    > communication.)  To restore that facility, I called upon
    > CFPreferencesSetAppValue() and CFPreferencesSynchronize().

    Look at persistentDomainForName in NSUserDefaults

    Trygve
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today