Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
My guess is that this tutorial may be dated and not take multitasking into account (although iOS 4 was released in mid 2010 so it seems like a 2011 tutorial aught to consider it...)

Anyways, in the application delegate, you don't want to be looking for applicationDidFinishLaunching (as that only happens if the app wasn't running in the background.) You would want applicationDidBecomeActive, instead.
 
thanks. I did put it there.
Code:
// in AppDelegate.m //

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // checks loads and creates plist if not available 
   [self prefs];
	
}

but I think it may be a simulator thang.
but it works most of time.
 
the code.

So now. For some reason it's exiting because it can't find the root.plist?
Here's what I use to make and check the prefs..

Code:
-(void)prefs
{
	//It is here that we set the defaults
	NSString *textValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"SystemMode"];
	NSString *commandValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"commandstr"];
	
	//If the first value is nil, then we know that the defaults are not set.
	if(textValue == nil)
	{
		//Get the bundle path
		NSLog(@"no prefences found");
		NSString *bPath = [[NSBundle mainBundle] bundlePath];
		NSString *settingsPath = [bPath stringByAppendingPathComponent:@"Settings.bundle"];
		NSString *plistFile = [settingsPath stringByAppendingPathComponent:@"Root.plist"];
		
		//Get the Preferences Array from the dictionary
		NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:plistFile];
		NSArray *preferencesArray = [settingsDictionary objectForKey:@"PreferenceSpecifiers"];
		
		//Temporary Variables
		NSDictionary *item;
		NSString *textEntry_Key;
		NSString *readOnly_Key;
		NSString *toogle_Key;
		NSString *slider_Key;
		NSString *colors_Key;
		
		//Loop through the array
		for(item in preferencesArray)
		{
			//Get the key of the item.
			NSString *keyValue = [item objectForKey:@"Key"];
			
			//Get the default value specified in the plist file.
			id defaultValue = [item objectForKey:@"DefaultValue"];
			
			if([keyValue isEqualToString:@"textEntry_key"])
				textEntry_Key = defaultValue;
			
			if([keyValue isEqualToString:@"readOnly_key"])
				readOnly_Key = defaultValue;
			
			if([keyValue isEqualToString:@"toogle_key"])
				toogle_Key = defaultValue;
			
			if([keyValue isEqualToString:@"slider_key"])
				slider_Key = defaultValue;
			
			if([keyValue isEqualToString:@"colors_key"])
				colors_Key = defaultValue;
		}
		
		//Now that we have all the default values.
		//We will create it here.
		NSDictionary *appPrerfs = [NSDictionary dictionaryWithObjectsAndKeys:
								   textEntry_Key, @"textEntry_key",
								   readOnly_Key, @"readOnly_key",
								   toogle_Key, @"toogle_key",
								   slider_Key, @"slider_key",
								   [NSNumber numberWithInt:1], @"slider_key",
								   [NSNumber numberWithInt:1], @"colors_key",
								   nil];
		
		//Register and save the dictionary to the disk
		[[NSUserDefaults standardUserDefaults] registerDefaults:appPrerfs];
		[[NSUserDefaults standardUserDefaults] synchronize];
		
		
	}
		NSLog(@"Pref Files: %@",textValue);
		NSLog(@"Pref file Command: %@",commandValue);
		
}

it's triggering but may not be writing. Cuz when I exit go to the Settings change something. It works fine?
It also only happens on the very first run of the app.

Any Ideas?? I'm so close to finishing this darn app. Just want it to work.

thanks
Ian

ps. is there a way to add a file to my bundle? I thought that was what the happening above.
 
Last edited:
small change.

Well it was getting triggered but.. this seems to have fixed it.

Code:
if([textValue isEqual:nil])

makes some sense.. I guess.

hope this helps some one..
later
Ian
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.