Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-23-2010, 05:07 PM   #1 (permalink)
Registered Member
 
fxshot's Avatar
 
Join Date: Feb 2009
Location: Stevenson Ranch, California
Posts: 75
fxshot is on a distinguished road
Default Changing NSUserDefaults with app in background OS4.0

I have a NSUserDefault BOOL value with a key @"MenuMusic". It is accessible to the user through the Settings App as a on/off switch.

When the game starts, I read in the user's prefrence with

Code:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
menuMusic = [prefs boolForKey:@"MenuMusic"];
Since os4.0 allows an application to be put in the Background and then brought back to the Foreground, I have implemented the following method

Code:
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
menuMusic = [prefs boolForKey:@"MenuMusic"];
}

in the hopes of being able to detect changes to the User Default settings while the app was in the background.

But it doesn't work. It keeps the setting it was originally set to, YES if it was YES and NO if it was NO.

Any ideas what I might be doing wrong. Or maybe just the correct way of updating User Settings.

As always, any help is appreciated. Thanks,

Mark


ps. or maybe I can turn off the ability to go into Enter Background.
__________________
Check out my app 'Dress Up Studio' on the iTunes Store -
http://itunes.apple.com/us/app/dress...359728350?mt=8
fxshot is offline   Reply With Quote
Old 06-23-2010, 07:44 PM   #2 (permalink)
Registered Member
 
fxshot's Avatar
 
Join Date: Feb 2009
Location: Stevenson Ranch, California
Posts: 75
fxshot is on a distinguished road
Default Figured it out ...

Added a synchronize before reading the default and it works.

Code:
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs synchronize];
menuMusic = [prefs boolForKey:@"MenuMusic"];
}
__________________
Check out my app 'Dress Up Studio' on the iTunes Store -
http://itunes.apple.com/us/app/dress...359728350?mt=8
fxshot is offline   Reply With Quote
Reply

Bookmarks

Tags
background, foreground, nsuserdefaults, skd 4.0

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 321
7 members and 314 guests
anothermine, Chickenrig, Domele, givensur, michaelhansen, PixelInteractive, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0