How to check a bool setting in my iphone app
- by dusk
I have a setting in Root.plist with Key = 'latestNews' of type PSToggleSwitchSpecifier and DefaultValue as a boolean that is checked. If I understand that correctly, it should = YES when I pull it in to my code. I'm trying to check that value and set an int var to pass it to my php script. What is happening is that my boolean is either nil or NO and then my int var = 0. What am I doing wrong?
int latestFlag;
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
BOOL latestNews = [prefs boolForKey:@"latestNews"];
if (latestNews)
latestFlag = 1;
else
latestFlag = 0;
NSString *urlstr = [[NSString alloc] initWithFormat:@"http://www.mysite.com/folder/iphone-test.php?latest=%d", latestFlag];
NSURL *url = [[NSURL alloc] initWithString:urlstr];
//these are auto-released
NSString *ans = [NSString stringWithContentsOfURL:url];
NSArray *listItems = [ans componentsSeparatedByString:@","];
self.listData = listItems;
[urlstr release];
[url release];