title: iPhone setting NSUserDefaults to nil when app is closed or in background
body: <p>I want to eliminate all of the variables saved into all fields of NSUserDefaults whenever the app is closed or running in the background for a certain amount of time - say 5 minutes.</p>
  
  <p>I tried to add a line to the app delegate of applicationDidFinishLaunching that looks like this:</p>
  
  <pre><code>if (UIApplicationStateBackground == TRUE) {
      NSUserDefaults *profiles = [NSUserDefaults standardUserDefaults];
  
      [profiles setObject:nil forKey:@"name1"];
      [profiles synchronize];
  }
  </code></pre>
  
  <p>I also added just this portion to the applicationWillTerminate:</p>
  
  <pre><code>NSUserDefaults *profiles = [NSUserDefaults standardUserDefaults];
  
      [profiles setObject:nil forKey:@"name1"];
      [profiles synchronize];
  </code></pre>
  
  <p>None of this seems to be working and I have no idea how to set a condition of 'if 5 minutes have surpassed of the application being in the background, delete the NSUserDefaults variables' - Any help?</p>