Skip to content

no background execution on ios #374

Description

@shehabmohamed0

on ios when I start the task on foreground everything works fine
but when I goes into background nothing happen at all

after looking at the actual ios implementation for the BGTaskScheduler I found out that the registered BGRefresh operation do nothing except waiting 25 seconds

  private static func handleAppRefresh(task: BGAppRefreshTask) {
    let queue = OperationQueue()
    let operation = AppRefreshOperation()
    
    task.expirationHandler = {
      operation.cancel()
    }
    
    operation.completionBlock = {
      // Schedule a new refresh task
      scheduleAppRefresh()

      task.setTaskCompleted(success: true)
    }
    
    queue.addOperation(operation)
  }
class AppRefreshOperation: Operation {
  override func main() {
    let semaphore = DispatchSemaphore(value: 0)
    
    // avoid non-platform thread
    DispatchQueue.main.asyncAfter(deadline: .now() + 25) {
      semaphore.signal()
    }
    
    semaphore.wait()
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions