问题描述
我正在尝试通过以下行安排后台任务:
I'm trying to schedule background task with such line:
WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: Date(timeIntervalSinceNow: TimeInterval(5) * 60), userInfo: nil, scheduledCompletion: self.scheduledCompletion)
其中
func scheduledCompletion(error: Error?) {
if error == nil { print("successfully scheduled application background refresh") }
else { print("error scheduling background refresh, error: \(error)") }
}
根据文档:
但是由于未知原因,它被安排在计划之后立即被调用.正在正确的时间调用后台刷新任务,并且在此之后未调用scheduledCompletion
.
But by unknown reason it is being called straightly after background refresh task is being scheduled. Background refresh task is being called on correct time, tho, and scheduledCompletion
is not being called after that.
那么这是文档中的错误,WatchKit中的错误还是我做错了什么?
So is it an error in documentation, bug in WatchKit or I'm doing something wrong?
推荐答案
尽管有文档说明,但scheduledCompletion
是计划任务的时间. WWDC16在11点的使您的手表应用保持最新状态会话中被提及: 23:
Despite documentation's description, scheduledCompletion
will be when the task will be scheduled. It was mentioned during WWDC16 Keeping Your Watch App Up to Date session at 11:23:
这篇关于当WKExtension.scheduleBackgroundRefresh应该调用ScheduledCompletion处理程序时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!