1 year ago
#308003
finebel
Time formatting in watchOS Complication
I want to display a timer as part of a complication. The timer should only display minutes and hours. For this purpose I have created a CLKRelativeDateTextProvider
and passed the corresponding units as an array to the initializer. So my current attempt looks like the following:
func currentTimelineEntry(for complication: CLKComplication) async -> CLKComplicationTimelineEntry? {
let relativeProvider = CLKRelativeDateTextProvider(date: Date(), style: .timer, units: [.hour, .minute])
let template = CLKComplicationTemplateGraphicCornerStackText(
innerTextProvider: relativeProvider,
outerTextProvider: CLKSimpleTextProvider(text: "Test")
)
return CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
}
Unfortunately this doesn't work right, because seconds are displayed alongside minutes and hours.
So for example the following screenshot was taken at the moment where the timer displayed 29 seconds.
Do you have any idea how I could achieve a format like H:mm to display only the hour and minute at every point in time (29 seconds should be displayed as 0:00). I don't understand why the passed units are being ignored.
Thanks for your help :-)...
PS: I'm also open to other approaches like working with SwiftUI to get the time properly displayed but all my attempts in this direction haven't been successful so far.
swift
watchkit
watchos
apple-watch-complication
0 Answers
Your Answer