Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sample code demonstrating how to determine which complication family was tapped to launch your watchOS app
// 1.
class ComplicationTimeKeeper{
static let shared = ComplicationTimeKeeper()
var utilitarianLarge : Date?
var utilitarianSmall : Date?
var circularSmall : Date?
var modularLarge : Date?
var modularSmall : Date?
// 2. in your CLKComplicationDataSource
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping ((CLKComplicationTimelineEntry?) -> Void)) {
// Call the handler with the current timeline entry
switch {
case .utilitarianLarge:
let date = Date()
ComplicationTimeKeeper.shared.utilitarianLarge = date
let template = CLKComplicationTemplateUtilitarianLargeFlat()
template.textProvider = CLKSimpleTextProvider(text:"Something")
let timelineEntry = CLKComplicationTimelineEntry(date: date, complicationTemplate: template)
default: handler(nil)
// 3. in your WKExtensionDelegate
func handleUserActivity(_ userInfo: [AnyHashable : Any]?) {
guard let userInfo = userInfo, let timelineDate = userInfo[CLKLaunchedTimelineEntryDateKey] as? Date else{
if let utilLarge = ComplicationTimeKeeper.shared.utilitarianLarge, == .orderedSame {
WKExtension.shared().rootInterfaceController?.pushController(withName: "SomeController", context: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.