Complication not getting installed for Watch App?

Viewed 894

I am trying to add complication to watch app (built using Swift UI) but when I select the "Complications" in the Watch app in iPhone it is showing no complications installed on the Watch app yet.

I have created a "ComplicationController" and added necessary code for "CircularSmall" and "ModularLarge" complication. Below is the code

class ComplicationController: NSObject, CLKComplicationDataSource {

    func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
        handler([])
    }

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

        if complication.family == .circularSmall
        {

            let template = CLKComplicationTemplateCircularSmallRingText()
            template.textProvider = CLKSimpleTextProvider(text: "12")
            let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
            handler(timelineEntry)

        } else if complication.family == .modularLarge {
            let template = CLKComplicationTemplateModularLargeStandardBody()
            template.headerTextProvider = CLKSimpleTextProvider(text: "Main Header")
            template.body2TextProvider = CLKSimpleTextProvider(text: "Main complication")
            template.body1TextProvider = CLKSimpleTextProvider(text: "Sub complication 1")
            let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
            handler(timelineEntry)

        } else {

            handler(nil)
        }
    }

    func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void)
    {
        switch complication.family
        {
        case .circularSmall:
            let template = CLKComplicationTemplateCircularSmallRingText()
            template.textProvider = CLKSimpleTextProvider(text: "12")

            handler(template)
        case .modularLarge:
            let template = CLKComplicationTemplateModularLargeStandardBody()
            template.headerTextProvider = CLKSimpleTextProvider(text: "Dummy Header")
            template.body2TextProvider = CLKSimpleTextProvider(text: "Dummy Body")
            template.body1TextProvider = CLKSimpleTextProvider(text: "Dummy Body 1")

            handler(template)
        default:
            handler(nil)
        }
    }

}

I am using Xcode Version 11.4 (11E146) & Watch OS 6 Attaching screenshots of the Complication Configuration Settings in Xcode.

Complication Configuration in Xcode

Watch App Complication section screenshot

3 Answers

Your code looks ok (I did not try to run it but have written several static and dynamic complications).Complication templates are installed on first install, then cached. If you ran your app with no, or with broken complications the first time, new overlays of installs will not refresh them to your new versions. Here is the drill:

  1. On device (watch) or Simulator, delete the app
  2. In Xcode, clean build folder
  3. if for sim, rebuild and run the Complication Scheme
  4. if for device, rebuild and run the std watch Scheme
  5. Do not use the Notification Scheme unless you are testing notifications
  6. Depending on your currentTimelineEntry calls, you might need to swap to a different face, then swap back and reCustomize with your complication

Good luck

  1. Check that your ComplicationController is included in the watch app extension target
  2. Run the Complication Scheme and check the logs (console)

If you are getting this error message:

Missing or Invalid Principal Class: (MyAPPExtension.ComplicationController). Please check 'ClockKit Complication - Principal' Class property in WatchKit Extension's Info.plist

Do this:

I had this problem, only went away when I updated Info.plist - ClockKit Complication - Principal Class to $(PRODUCT_MODULE_NAME).ComplicationController

ComplicationController was already assigned to Watchkit Extension Target. Info.plist by default just has ComplicationController value set.

After that the complications are showing fine! I think this issue appeared when I updated Xcode to the latest version and it expects the property to be like the above mentioned.

Related