title: iOS Destroy UI when app is in background
body: <p>I'm using CoreLocation to use my app in background.
  More precisely, I'm using Significant changes (<code>startmonitoringsignificantlocationchanges</code>) or Always On (<code>startupdatinglocation</code>) depending on server config.</p>
  
  <p>On these two cases, application lifecycle is different :</p>
  
  <ul>
  <li>With <code>startmonitoringsignificantlocationchanges</code> application is registered to OS, and the app is frozen or killed by OS. It will be waked up when a new location event will be received, and <code>didFinishLaunchingWithOptions</code> will be called with a specific launch key</li>
  <li>With <code>startupdatinglocation</code>, application will run until <code>stopupdatinglocation</code> is called. Then application will be frozen until the OS kill the app when more memory is needed</li>
  </ul>
  
  <p><strong>My question</strong></p>
  
  <p>I'm using a SDK (developed by my company) which should run in background base on CoreLocation services. The SDK is initialized and attached to the <code>UIApplicationDelegate</code> class.</p>
  
  <p>I would like to kill all UI elements after a delay in background to avoid useless data processing in UI (timers, refresh, callbacks, ...), because the app is running in background with <code>startUpdatingLocation</code>.</p>
  
  <p>UI Will be launched (from zero) later in <code>applicationDidBecomeActive</code>.</p>
  
  <p>Here is what I tried :</p>
  
  <p>1/ Removing automatic storyboard launch in project settings</p>
  
  <p>2/ Start the storyboard manually in <code>didFinishLaunchingWithOptions</code></p>
  
  <pre><code>// Instantiate the initial view controller object from the storyboard
  UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
  _window = [[UIWindow alloc] init];
  _window.rootViewController = [story instantiateInitialViewController];
  [_window makeKeyAndVisible];
  </code></pre>
  
  <p>3/ I (tried to) destroy the UI in <code>applicationDidEnterBackground</code> </p>
  
  <pre><code>UINavigationController *vc = (UINavigationController *)_window.rootViewController;
  _window.rootViewController = nil;
  _window = nil;
  </code></pre>
  
  <p>4/ I scheduled a timer every 2s with a NSLog inside in a view controller</p>
  
  <p>5/ With the code above, the view controller is not destroyed and timer is still called when the app is in background</p>
  
  <p>Any idea ?</p>