When an iPad app comes from background to foreground , I want to alter the barButtons on home view based on Preference settings.
1. Put app in background by pushing the round button
2. I Run Settings App , and set a preference for the app to YES
3. Bring app to foreground by touching the icon
4. the AppDelegate is set as an observer of a Notification in applicationDidFinishLoading using:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleEnteredForeground

name:UIApplicationWillEnterForegroundNotification object:nil];
5. The viewController for the home view is rootTableViewController
6. In the handler for the EnterForegroundNotification in appDelegate.m , I call a method in the viewController
[[self rootTableViewController] doit];
6. In doit , I check the preference this way:
BOOL bImportRecipes = [[NSUserDefaults standardUserDefaults] boolForKey:@"Import_Recipes"];
and then set the BarButtons accordingly.
The problem is this usually work about half the time. It is found to be Yes about half the time.
The Notification arrives each time and is handled everytime. The problem is in reading the
Preferences for the app
What can I do?
---
I tried a work around. I move the reading of the Preference to the Notification
handler in AppDelegate. I then send the preference value to
setImportButton method of rootTableViewController as a parameter.
I also changed the Notification to:
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(handleEnteredForeground

name:UIApplicationDidBecomeActiveNotification object:nil];
I now have a predictable failure of the preference reading when handling
the on the first try and a success on
the second try. That is:
1. Put app in Background - round button
2. Set Preference to YES in Settings app
3. Bring to foreground - touch icon
4. Preference is read as NO and passed to - (void)doit

BOOL)bDoImport
5. Put app in Background
6. Bring app to Foreground
7. Preference is read correctly as YES
Is this a bug?