title: ios 13 objective-c background task request
body: <p>I've got a question with objective-c and background task request.</p>
  
  <p>Restricted to background modes with ios 13.</p>
  
  <p>My App does not run in the background more than 30 seconds.</p>
  
  <p>Background modes changed with ios 13.</p>
  
  <p>I need to register a background task with objective-c like this:</p>
  
  <pre><code>BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.SO.apprefresh", using: nil) { task in
      self.scheduleLocalNotification()
      self.handleAppRefreshTask(task: task as! BGAppRefreshTask)
  }
  </code></pre>
  
  <p>and I need schedule when app goes to background</p>
  
  <pre><code>func scheduleAppRefresh() {
      let request = BGAppRefreshTaskRequest(identifier: "com.SO.apprefresh")
      request.earliestBeginDate = Date(timeIntervalSinceNow: 2 * 60) // App Refresh after 2 minute.
      do {
          try BGTaskScheduler.shared.submit(request)
      } catch {
          print("Could not schedule app refresh: \(error)")
      }
  }
  </code></pre>