Created
July 3, 2019 15:05
-
-
Save mecid/b9a746d651c7d855368ad2dddcea9d15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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