Skip to content

Instantly share code, notes, and snippets.

@mecid
Created July 3, 2019 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mecid/b9a746d651c7d855368ad2dddcea9d15 to your computer and use it in GitHub Desktop.
Save mecid/b9a746d651c7d855368ad2dddcea9d15 to your computer and use it in GitHub Desktop.
import UIKit
import BackgroundTasks
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BGTaskScheduler.shared.register(
forTaskWithIdentifier: "pl.snowdog.example.train",
using: DispatchQueue.global()
) { task in
self.handleMLTrain(task)
}
return true
}
private func scheduleMLTrain() {
do {
let request = BGProcessingTaskRequest(identifier: "pl.snowdog.example.train")
request.requiresExternalPower = true
request.requiresNetworkConnectivity = true
try BGTaskScheduler.shared.submit(request)
} catch {
print(error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment