0

Below code i have used to write certain task in background mode.But this executes only for 3mins after it ends task. So i would like to execute particular task till it finishes.

func registerBackgroundTask() {
    backgroundTask = UIApplication.shared.beginBackgroundTask { [weak self] in
        self?.endBackgroundTask()   
    }
    assert(backgroundTask != UIBackgroundTaskInvalid)
}

func endBackgroundTask() {
    print("Background task ended.")
    AppConstants.sharedInstance.scheduleLocalNotification(message: "Background task ended.", title: "status!")
    UIApplication.shared.endBackgroundTask(backgroundTask)
    backgroundTask = UIBackgroundTaskInvalid
}

self.registerBackgroundTask()
self.perform(#selector(self.backgroundTimer(challengeId:)), with: "\(tag)", afterDelay:600)
Riajur Rahman
  • 1,976
  • 19
  • 28
Malathi
  • 47
  • 5

1 Answers1

0

As found in this doc, only pre-defined (by Apple) tasks (in Table 3-1 of the doc) are allowed to run indefinitely. You have no way to execute your task till it finishes. But if you are targeting jail broken devices, you can do it by writing daemon. This seems not the case for you. So, you have no luck.

beshio
  • 794
  • 2
  • 7
  • 17