Building a WatchKit Complication

Episode #202 | 13 minutes | published on January 4, 2016 | Uses watchOS-2
Subscribers Only
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)
})
blog comments powered by Disqus