Alex Stone
Alex Stone

Reputation: 47328

iOS WatchOS5 - How to support more than one complication family for a watch app?

I have one complication working for my apple watch app and I would like to add a second style. I put up a very basic prototype, but don't see it available for selection on the watch face. So I'm trying to troubleshoot the issue:

Can I my app support more than one complication? Can I have two complications running at the same time on the watch face? (Or is it either-or case and if I have one, the iOS would not show the second one?) I tried adding a new watch face, but it would not allow me.

Is CLKComplicationTemplateModularSmallRingText a valid template for ModularSmall type of complication?

    func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {

        if complication.family == .modularSmall {
            let template = CLKComplicationTemplateModularSmallRingText()
            template.ringStyle = .open
            template.fillFraction = 0.3

            let testProvider = CLKSimpleTextProvider(text: "TST", shortText: "S")
            sleep.tintColor = UIColor.green
            template.textProvider = testProvider
            template.tintColor = UIColor.green

            let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)

            // Pass the entry to ClockKit.
            handler(entry)
        }
        else if complication.family == .graphicRectangular {
            let template = CLKComplicationTemplateGraphicRectangularLargeImage()
//this complication works...
}

Placeholder template is the same for now:

func getPlaceholderTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {

    // Pass the template to ClockKit.
    if complication.family == .modularSmall {
        let template = CLKComplicationTemplateModularSmallRingText()
//...

Complication supported families

I see one error in the complication placeholder file (but I'm testing on a 44 mm device) - will fix it and see what's going on. Am I returning a wrong image or wrong template type for the Modular complication? I want a round ring gauge

enter image description here

Upvotes: 0

Views: 624

Answers (1)

Alex Stone
Alex Stone

Reputation: 47328

Turns out I was misled by Apple's documentation. I needed to use GraphicCircular complication(new in WatchOS5) type as opposed to modular (old watch faces)

func circularTemplate() -> CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText{
    let template = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText()
    let gauge = CLKSimpleGaugeProvider(style: .ring, gaugeColor: UIColor.green), fillFraction: 0.3)
    template.gaugeProvider = gauge

    let random = arc4random() % 999

    let middle = CLKSimpleTextProvider(text: "4.5", shortText: "4")
    middle.tintColor = kRGBColorFromHex(0x657585)
    template.tintColor = kRGBColorFromHex(0x657585)
    template.centerTextProvider = middle

    let bottom = CLKSimpleTextProvider(text: "-\(random)", shortText: "1..")
    template.bottomTextProvider = bottom
    return template
}

New style:

enter image description here

Old Style: enter image description here

Upvotes: 1

Related Questions