Complication on Apple Watch not showing my information

802 views Asked by At

I'm faced with a problem with complications on Apple Watch.

I'm trying to display images and some texts on a complication. I can select the complication on the Clock interface but it shows nothing that the app title and two lines full of "-" character.

The complication should show my information instead, but I don't see what is wrong in my code

Here is the code:

func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
    // This method will be called once per supported complication, and the results will be cached
    handler(nil)
    var template: CLKComplicationTemplateModularLargeColumns?
    switch complication.family {
    case .modularSmall:
        template = nil
    case .modularLarge:
        let modularLargeTemplate =
            CLKComplicationTemplateModularLargeColumns()
        modularLargeTemplate.row1ImageProvider =
            CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
        modularLargeTemplate.row2ImageProvider =
            CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
        modularLargeTemplate.row3ImageProvider =
            CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)

        modularLargeTemplate.row1Column1TextProvider = CLKSimpleTextProvider(text: "User: ")
        modularLargeTemplate.row1Column2TextProvider = CLKSimpleTextProvider(text: "ok")

        modularLargeTemplate.row2Column1TextProvider = CLKSimpleTextProvider(text: "Car: ")
        modularLargeTemplate.row2Column2TextProvider = CLKSimpleTextProvider(text: "ok")

        modularLargeTemplate.row3Column1TextProvider = CLKSimpleTextProvider(text: "Environment: ")
        modularLargeTemplate.row3Column2TextProvider = CLKSimpleTextProvider(text: "ok")

        template = modularLargeTemplate
    case .utilitarianSmall:
        template = nil
    case .utilitarianLarge:
        template = nil
    case .circularSmall:
        template = nil
    default:
        template = nil
    }
    handler(template)

}

If I place a breakpoint in the middle of the code, the debugger trigger it, so it executes this code. However nothing is displayed like I want.

Can you find what is wrong/missing?

1

There are 1 answers

1
Vojta Rujbr On BEST ANSWER

This is just the template, you need to take care of getCurrentTimelineEntry, the simplest would be just to return the same entry as template (see below). And as other mentioned in comments, you need to delete handler(nil) in your code as well.

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
        getLocalizableSampleTemplate(for: complication) {template in
            guard let template = template else {
                handler(nil)
                return
            }
            handler(CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template))
        }
    }