0

How can I add settings to an app? I've never done this before and I don't know where to begin. I would like to make an app where user would set his/her info (like time interval, gender, ...). Uncle Google gives me results that help users of iOS 5 not developers.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
frankC
  • 5
  • 6

1 Answers1

1

Keywords are: Settings.bundle and NSUserDefaults. There is a lot information in Google.

Also, check out this awesome framework: InAppSettingsKit.

Good luck.

dreamzor
  • 5,795
  • 4
  • 41
  • 61
  • Thank you. It was useful. Got it working. Just one more thing... I open my app, it shows I'm a male (default setting). Then I go to Settings->my app->Gender setting and change it to female... when I go back to my app, a label (i have some to display settings for now) showing gender doesn't change. I set label text in viewDidLoad. Any ideas? I followed these instructions: http://www.iphonesdkarticles.com/2008/08/application-preferences.html – frankC Sep 23 '12 at 18:48
  • Glad to help you. What happens if you restart your app? Also, try method `applicationWillEnterForeground`. `viewWillAppear` doesn't really get called after app reopening from background. – dreamzor Sep 23 '12 at 18:49
  • `viewDidLoad` is called just when your ViewController is created. It's even further from `viewWillAppear` :) – dreamzor Sep 23 '12 at 18:57
  • in app delegate: `- (void)applicationWillEnterForeground:(UIApplication *)application { NSString *value = [[NSUserDefaults standardUserDefaults] stringForKey:@"gender"]; }` in view controller: `AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate]; NSString *test = appDelegate.value;` test gives me (null) :/ – frankC Sep 23 '12 at 19:12
  • Is `value` a local variable? If yes, then, of course, it won't work, You need to set `NSString *value` as a property of the `AppDelegate` (something like public class variable in c++) – dreamzor Sep 23 '12 at 19:17
  • What does `NSLog(@"%@", value)` in `applicationWillEnterForeground` say? Is it called? Also, make sure you write `value = [defaults...]` or even `self.value`, **not** the `NSString *value = ...`, in case you are creating local variable. – dreamzor Sep 23 '12 at 19:25
  • Why not just call `[[..defaults..] stringForKey:@"gender"]` ? Do you really need the `value` here?:) Try using `()([[UIApplication....]])` – dreamzor Sep 23 '12 at 19:33
  • Google what methods are there to see that app is active, view is loaded, will appear and when they are called. Or just put NSLogs to see that yourself. Look here: http://stackoverflow.com/questions/3639859/handling-applicationdidbecomeactive , it tells how to interact properly. – dreamzor Sep 23 '12 at 19:44