title: Swift iOS backgroundTaskIdentifier or Background Fetch
body: <p>Swift 2.0 background task (backgroundTaskIdentifier and Background Fetch) </p>
  
  <p>Notice : I used two method background fetch and backgroundTaskIdentifier but cancel background process   </p>
  
  <blockquote>
    <p>Hi , this sample code working in XCode debug monitor (Active &amp; Background mode) , but after disconnected iPhone device and launch manually application -> press home and go to background mode -> after a while app closed (suspended).</p>
  </blockquote>
  
  <p>there is anyway to prevent this or having a new idea to keep background process alive ? </p>
  
  <pre><code> func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -&gt; Bool {
      backgroundTaskIdentifier = UIApplication.sharedApplication().beginBackgroundTaskWithExpirationHandler(
      {
          NSTimer.scheduledTimerWithTimeInterval(20, target: self, selector: "update", userInfo: nil, repeats: true)
      })
      NSTimer.scheduledTimerWithTimeInterval(20, target: self, selector: "update", userInfo: nil, repeats: true)
      return true
  }
  
  
  func update()
  {
      print("Hi There")
  }
  </code></pre>