Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't my Apple Watch complication show anything?

I created an app using Xcode's "iOS App with Watchkit App" template, went into TARGETS and checked Complications Configuration > Supported Families > Graphic Corner. I opened ComplicationController.swift in the Extension and modified getCurrentTimelineEntry():

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText()
    cornerTemplate.outerTextProvider = CLKSimpleTextProvider(text: "Outer")
    cornerTemplate.innerTextProvider = CLKSimpleTextProvider(text: "Inner")
    let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: cornerTemplate)
    handler(entry)
}

I also modified getLocalizableSampleTemplate() to provide a sample, and this is not working either:

func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
    let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText()
    cornerTemplate.outerTextProvider = CLKSimpleTextProvider(text: "Outer")
    cornerTemplate.innerTextProvider = CLKSimpleTextProvider(text: "Inner")
    handler(cornerTemplate)
}

When I run the app in the simulator or on my phone/watch and select the complication as one of the graphic corners, I expect to see "Outer" and "Inner". Instead it shows the name of my app for one and "---" for the other.

What am I doing wrong?

like image 940
Robert Avatar asked Nov 06 '22 18:11

Robert


1 Answers

This is some of my code that is currently working:

var graphicCornerComplication: CLKComplicationTimelineEntry? {

        guard #available(watchOSApplicationExtension 5.0, *) else {
            return nil
        }

        let innerTextProvider = CLKSimpleTextProvider(text: "Inner")
        let outerTextProvider = CLKSimpleTextProvider(text: "Outer")

        let template = CLKComplicationTemplateGraphicCornerStackText()
        template.outerTextProvider = outerTextProvider
        template.innerTextProvider = innerTextProvider

        let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
        return timelineEntry

    }

A few considerations:

  • Have you implemented your getLocalizableSampleTemplate code? This should be the first thing you do when configuring complications. You should have something ready to show immediately when users scroll through complication slots and see yours. If you don't, that could be why you're seeing the dashes instead of your intended text.

  • Is your complication data source correctly assigned? Under Targets > Your WatchKit Extension > Complications Configuration > Data Source Class, make sure ComplicationController is assigned.

  • Your entry could be coming up nil if you're working on an older version of WatchOS.

EDIT - To clarify, graphicCornerComplication is just a property that I have added to some of my models so that I can quickly get a timeline entry by just calling graphicCornerComplication on them. In use, it looks something like this:

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
    switch complication.family {
    case .graphicCorner:
        let graphicCornerComplication = dataModel.graphicCornerComplication
        handler(graphicCornerComplication)
    default:
        handler(nil)
    }
}
like image 110
bkSwifty Avatar answered Nov 14 '22 22:11

bkSwifty