title: swift background fetch not working
body: <p>I have the following code in my AppDelegate:</p>
  
  <pre><code>func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {        
          application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
  
          application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
  
          return true
      }
  
  func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -&gt; Void) {
  
      completionHandler(UIBackgroundFetchResult.NewData)
      getData()
  }
  
  func getData(){
  
      // function that gets certain data from the server and notifies the 
      // user of the info fetched
  }
  </code></pre>
  
  <p>I am facing two problems here:</p>
  
  <ol>
  <li><p>the first problem is that the background fetch is never executed unless I click on "Debug>simulate background fetch". i waited for it indefinitely and it was never called on its own.</p></li>
  <li><p>The second problem is that when i click on simulate background fetch while my app is still open, the simulator exists the app and then performs the background fetch, even though the background fetch should still work even while the application is running and without closing it.</p></li>
  </ol>
  
  <p>Am I missing any code related to background fetch ? Or is there any wrong code ? This is the only code I have written related directly to background fetch other than adding background fetch to the capabilities. </p>