I have followed directions in several books and suggestions on some forums but I have issues with my app crashing when I try and set user preferences. I have the following lines on my "done" method in my flipscreenViewController:
- (IBAction)done
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:musicOnOff.on forKey:kMusicPreference];
[userDefaults setObject:trackSelection forKey:kTrackPreference];
[self.delegate flipsideViewControllerDidFinish:self];
}
And the following methods in my mainViewController:
-(void)initialDefaults
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:YES forKey:kMusicPreference];
[userDefaults setObject:@"Infinity" forKey:kTrackPreference];
}
-(void) setvaluesFromPreferences
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
BOOL musicSelection = [userDefaults boolForKey:kMusicPreference];
NSString *trackSelection = [userDefaults objectForKey:kTrackPreference];
if(musicSelection == YES)
{
if([trackSelection isEqualToString:@"Infinity"])
song = [[BGMusic alloc]initWithPath:
[[NSBundle mainBundle] pathForResource:
@"Infinity" ofType:@"m4a"]];
else if([trackSelection isEqualToString:@"Energy"])
song = [[BGMusic alloc]initWithPath:
[[NSBundle mainBundle] pathForResource:
@"Energy" ofType:@"m4a"]];
else if([trackSelection isEqualToString: @"Enforcer"])
song = [[BGMusic alloc]initWithPath:
[[NSBundle mainBundle] pathForResource:
@"Enforcer" ofType:@"m4a"]];
else if([trackSelection isEqualToString: @"Continuum"])
song = [[BGMusic alloc]initWithPath:
[[NSBundle mainBundle] pathForResource:
@"Continuum" ofType:@"m4a"]];
else if([trackSelection isEqualToString: @"Pursuit"])
song = [[BGMusic alloc]initWithPath:
[[NSBundle mainBundle] pathForResource:
@"Pursuit" ofType:@"m4a"]];
[song setRepeat:YES];
counter = 0;
}
else
[song close];
}
If anyone out there could please help me see what I am doing wrong it would be much appreciated.
Chuck