当WKExtension.scheduleBackgroundRefresh应该调用ScheduledCompletion处理程序时? [英] When WKExtension.scheduleBackgroundRefresh is supposed to call scheduledCompletion handler?

查看:203
本文介绍了当WKExtension.scheduleBackgroundRefresh应该调用ScheduledCompletion处理程序时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下行安排后台任务:

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系统在调用后调用的块 后台应用刷新任务已完成.

scheduledCompletion A block that is called by the system after the background app refresh task has completed.

但是由于未知原因,它被安排在计划之后立即被调用.正在正确的时间调用后台刷新任务,并且在此之后未调用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处理程序时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆