私のアプリにバックグラウンドプロセスがあります。コードは次のとおりです。ios9のバックグラウンドタイマー
@available(iOS 10.0, *)
func startTimer() {
timer2?.invalidate()
timer2 = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: { (t) in
if UIApplication.shared.applicationState == .background {
NSLog("tic background \(UIApplication.shared.backgroundTimeRemaining)")
if UIApplication.shared.backgroundTimeRemaining < 10 {
}
}
})
timer2?.fire()
}
ただし、iOS10でのみ動作します。以前のバージョンのiOS用に書き直す方法はありますか?
iOS9での問題は何ですか? – shallowThought
'scheduledTimer(withTimerInterva:repeatedats:ブロック)'はios 10以降でのみ利用可能です –
をご覧ください。 http://stackoverflow.com/a/24007862/1457385 – shallowThought