Complication Won't Update

Complication won't update

Your data source is missing the methods that are responsible for handling the scheduled update.

At the start of a scheduled update, ClockKit calls either the requestedUpdateDidBegin or requestedUpdateBudgetExhausted method, depending on the state of your complication’s time budget. You must implement one or both of those methods if you want to add data to your timeline. Your implementation of those methods should extend or reload the timeline of your complication as needed. When you do that, ClockKit requests the new timeline entries from your data source. If you do not extend or reload your timeline, ClockKit does not ask for any new timeline entries.

Here's how you can reload the timeline once your scheduled update occurs:

// MARK: - Responding to Scheduled Updates

func requestedUpdateDidBegin() {
let server=CLKComplicationServer.sharedInstance()
for complication in server.activeComplications {
server.reloadTimelineForComplication(complication)
}
}

You should also implement requestedUpdateBudgetExhausted().

Keep in mind that scheduled updates can only occur every 10 minutes; it's not possible to update your complication every second. Also consider that updating too often might exhaust your update budget:

Specify a date as far into the future as you can manage. Do not ask the system to update your complication within minutes. Instead, provide data to last for many hours or for an entire day. If your budget is exhausted, the next scheduled update does not occur until after your budget is replenished.

WatchKit complication not updating

When your watch app is running in background, you should use WKWatchConnectivityRefreshBackgroundTask to get the data from iPhone.

WKWatchConnectivityRefreshBackgroundTask

Currently WKWatchConnectivityRefreshBackgroundTask, so you watch won't get the data until it goes foreground.

Then you need to manually update your complication yourself.

Can't get Apple Watch complication to update in WatchOS 3

WKRefreshBackgroundTask do not update anything itself, it just allows your app to go to active state and run code (placed somewhere around print("Task received") line) that will update your complication. Remember that number of WKRefreshBackgroundTasks is limited.

Complication can be updated such way:

let server = CLKComplicationServer.sharedInstance()

// if you want to add new entries to the end of timeline
server.activeComplications?.forEach(server.extendTimeline)

// if you want to reload all the timeline, which according to snippets looks like your case
server.activeComplications?.forEach(server.reloadTimeline)

This will cause system to call getCurrentTimelineEntry(for:withHandler:) methods of your CLKComplicationDataSource, where you can prepare and return updated entries.

More about complications update in documentation. More about background tasks in WWDC16 session.

Apple watch complication not refreshing in the background when using HealthKit queries

Attempting to asynchronously fetch (HealthKit) data within the complication controller will be unreliable.

In addition, trying to fetch or compute within the complication controller will needlessly use up the execution time budget that is allotted to your complication.

Apple recommends that you fetch the data and cache it before the complication data source needs it.

The job of your data source class is to provide ClockKit with any requested data as quickly as possible. The implementations of your data source methods should be minimal. Do not use your data source methods to fetch data from the network, compute values, or do anything that might delay the delivery of that data. If you need to fetch or compute the data for your complication, do it in your iOS app or in other parts of your WatchKit extension, and cache the data in a place where your complication data source can access it. The only thing your data source methods should do is take the cached data and put it into the format that ClockKit requires.

WatchOS 2 Complication Scheduled Update In Background

I would think you need to implement:

func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: ((CLKComplicationTimelineEntry?) -> Void))

The method you have implemented getTimelineEntriesForComplication(complication: CLKComplication, beforeDate... is only called when the complication server is gathering timeline entries for forward time travel.

Given the scenario you describe, I would strongly recommend supporting forward time travel by implementing:

func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) {
handler([.Forward])
}

And

func getTimelineEndDateForComplication(complication: CLKComplication, withHandler handler: (NSDate?) -> Void) {
let date: NSDate = // Your date
handler(date)
}

Using dataApi to update complication

It sounds to me like you want a ProviderUpdateRequester in your WearableListenerService. When you receive changed data from the handheld, make a call like this:

new ProviderUpdateRequester(context, new ComponentName(context, "myComplicationClass"))
.requestUpdateAll();

Obviously, you'll need to be storing the changed data locally (on the watch) before doing so - in a database, SharedPreferences, or whatever - as there's no way to directly pass the data to your complication provider. But you're probably already doing that to make your provider work anyway.

Documentation is here: https://developer.android.com/reference/android/support/wearable/complications/ProviderUpdateRequester.html



Related Topics



Leave a reply



Submit