wkrefreshbackgroundtask

WatchOS 3 WKApplicationRefreshBackgroundTask didReceiveChallenge

久未见 提交于 2019-12-21 06:28:40
问题 I have finally (ignoring the sample code which I never saw work past "application task received, start URL session") managed to get my WatchOS3 code to start a background URL Session task as follows: func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) { for task in backgroundTasks { if let refreshTask = task as? WKApplicationRefreshBackgroundTask { // this task is completed below, our app will then suspend while the download session runs print("application task received, start URL

Updating complication with Swift 3 and background task

泪湿孤枕 提交于 2019-12-09 16:39:04
问题 For watchOS 3, Apple suggests updating the complication with WKRefreshBackgroundTask instead of using getNextRequestedUpdateDate . How can I determine the time between two updates using the new approach? I would only hack my data requesting (from an url) into getCurrentTimelineEntry and would update the complication, but I think that's not really what Apple would recommend. A short code example would be a big help. 回答1: I generally covered this in a different answer, but I'll address your

When WKExtension.scheduleBackgroundRefresh is supposed to call scheduledCompletion handler?

邮差的信 提交于 2019-12-07 21:17:08
问题 I'm trying to schedule background task with such line: WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: Date(timeIntervalSinceNow: TimeInterval(5) * 60), userInfo: nil, scheduledCompletion: self.scheduledCompletion) where func scheduledCompletion(error: Error?) { if error == nil { print("successfully scheduled application background refresh") } else { print("error scheduling background refresh, error: \(error)") } } According to documentation: scheduledCompletion A block that

Updating complication with Swift 3 and background task

别等时光非礼了梦想. 提交于 2019-12-04 03:56:06
For watchOS 3, Apple suggests updating the complication with WKRefreshBackgroundTask instead of using getNextRequestedUpdateDate . How can I determine the time between two updates using the new approach? I would only hack my data requesting (from an url) into getCurrentTimelineEntry and would update the complication, but I think that's not really what Apple would recommend. A short code example would be a big help. I generally covered this in a different answer , but I'll address your specific question here. You're right that you shouldn't hack the complication controller to do any

WKURLSessionRefreshBackgroundTask isn't called when attempting to do background refreshes in watchOS

旧巷老猫 提交于 2019-11-30 09:36:55
I'm working on a complication to get scheduled data from a web service. Every 20-30 minutes (or manually), I am scheduling a WKRefreshBackgroundTask to do this. As suggested by Apple, I want the OS to handle the fetching of this data via a background NSURLSession . This is the function I use to download the data I need: func scheduleURLSession() { print("\nScheduling URL Session...") let backgroundSessionConfig:URLSessionConfiguration = URLSessionConfiguration.background(withIdentifier: NSUUID().uuidString) backgroundSessionConfig.sessionSendsLaunchEvents = true let backgroundSession =

WKURLSessionRefreshBackgroundTask isn't called when attempting to do background refreshes in watchOS

你。 提交于 2019-11-29 14:39:39
问题 I'm working on a complication to get scheduled data from a web service. Every 20-30 minutes (or manually), I am scheduling a WKRefreshBackgroundTask to do this. As suggested by Apple, I want the OS to handle the fetching of this data via a background NSURLSession . This is the function I use to download the data I need: func scheduleURLSession() { print("\nScheduling URL Session...") let backgroundSessionConfig:URLSessionConfiguration = URLSessionConfiguration.background(withIdentifier: