6

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?

Robert
  • 6,660
  • 5
  • 39
  • 62

1 Answers1

1

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)
    }
}
swiftyboi
  • 2,965
  • 4
  • 25
  • 52
  • I did implement `getLocalizableSampleTemplate`. Didn't make any difference either scrolling through the slots or when selected, so I didn't mention it initially. It's now added to the question. Data source class is set to `$(PRODUCT_MODULE_NAME).ComplicationController`, which is the default value. I'm working with current versions of Xcode (10.2.1), WatchOS (5.2), and iOS (12.2) in the simulator and real device. – Robert Apr 24 '19 at 04:47
  • Your working code looks functionally identical to mine except that you're defining `var graphicCornerComplication` instead of one of the functions in `CLKComplicationDataSource`. I don't see that in the docs... is it something I need to define? Where is it getting called? – Robert Apr 24 '19 at 04:50
  • graphicCornerComplication is just a property I added to some of my models so that I can display the relevant information as a complication. I've updated the answer to clarify this. – swiftyboi Apr 24 '19 at 14:44
  • If your code looks fine, it looks like something else is going on. Do you have an active scheme for the complication? – swiftyboi Apr 24 '19 at 14:45
  • I think I have an active scheme. Sorry to be dense but I'm not quite sure what that means. When I edit the default scheme it shows "Watchkit Extension" as one of the build targets. Is there more to it than that? – Robert Apr 25 '19 at 08:12
  • The complication showing App title and dashes in lower text lines occurs when the template is absent or malformed, for example when images can not be displayed. I had this experience when, per Apple Guidelines, I tried using scaleable PDFs instead of PNG. Switched back to PNG, and all was fine. – BlueskyMed May 17 '20 at 12:50