Episode #202

Building a WatchKit Complication

13 minutes
Published on January 4, 2016

This video is only available to subscribers. Get access to this video and 527 others.

In this episode we are joined again by Conrad Stoll

Episode Links

Create a Template for a Modular Large Complication

if complication.family == .ModularLarge {
    let template = CLKComplicationTemplateModularLargeStandardBody()

    let headerTextProvider = CLKSimpleTextProvider(text: "Order Status")
    template.headerTextProvider = headerTextProvider

    let titleTextProvider = CLKSimpleTextProvider(text: "Pumpkin")
    template.body1TextProvider = titleTextProvider

    let timeTextProvider = CLKRelativeDateTextProvider(date: NSDate(timeIntervalSinceNow: 118), style: .Timer, units: .Second)
    template.body2TextProvider = timeTextProvider

    handler(template)
}

Create a Timeline Entry with Template

let entry = CLKComplicationTimelineEntry()
entry.complicationTemplate = template
entry.date = NSDate()

handler(entry)

Refresh Complication from Apple Watch App

import ClockKit

let complicationServer = CLKComplicationServer.sharedInstance()

for complication in complicationServer.activeComplications {
    complicationServer.reloadTimelineForComplication(complication)
}

Animate WatchKit Interface Controller Changes

self.animateWithDuration(0.5, animations: {
    self.group?.setHeight(40)
    self.group?.setWidth(40)
    self.group?.setCornerRadius(20)
    self.button?.setAlpha(0)
})

This episode uses Watchos 2.