How to have Text next to CLKRelativeDateTextProvider

239 Views Asked by At

I am building watchOS complications and i want to have a timer that counts down what i have made using the following:

func createUtilitarianLargeTemplate(prayer: Prayer?) -> CLKComplicationTemplate {
    let myComplicationTemplate = CLKComplicationTemplateUtilitarianLargeFlat()
    let dateProvider = CLKRelativeDateTextProvider()

    if let prayer = prayer {
        dateProvider.date = prayer.prayerTime.prayerDate
        dateProvider.calendarUnits = [.hour, .minute]
        dateProvider.relativeDateStyle = .timer
    }

    myComplicationTemplate.textProvider = dateProvider

    return myComplicationTemplate
}

But i want to show some text next to the timer in an UtilitarianLarge complication family. How is that possible as i can't set text in the dateProvider.

What I want to achieve is the following String:

GBT * 15:24:12

So I want to have "GBT * " in front of the timer. How is that possible? Somehow it must be possible as I have seen other complications on the Appstore achieving this

1

There are 1 best solutions below

0
On

It took them until watchOS 6 to add init(format:_:) to CLKTextProvider.

let myComplicationTemplate = CLKComplicationTemplateUtilitarianLargeFlat()
let dateProvider = CLKRelativeDateTextProvider()

dateProvider.date = Date()
dateProvider.calendarUnits = [.hour, .minute]
dateProvider.relativeDateStyle = .naturalAbbreviated

let finalText = CLKTextProvider(format: "GBT * %@", dateProvider)

myComplicationTemplate.textProvider = finalText

For watchOS 5 and prior, this is the only good way to do it...