Skip to content

Instantly share code, notes, and snippets.

@vnsam
Last active February 25, 2019 16:05
Show Gist options
  • Save vnsam/7d7c9f152549560c53e0b2530b2fc98f to your computer and use it in GitHub Desktop.
Save vnsam/7d7c9f152549560c53e0b2530b2fc98f to your computer and use it in GitHub Desktop.
Timer - App background support
import Foundation
extension Timer {
static func scheduleTimerEnablingBackground(timeInterval: TimeInterval, target: Any,
selector: Selector, userInfo: Any?,
repeats: Bool) -> Timer {
// Enable background expiration
UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
let timer = Timer.scheduledTimer(timeInterval: timeInterval,
target: target,
selector:selector,
userInfo: userInfo,
repeats: repeats)
return timer
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment