Contents

getWidgetConfiguration(from:completionHandler:)

Returns a configuration object that defines the WidgetKit replacement for the provided ClockKit complication.

Declaration

optional func getWidgetConfiguration(from complicationDescriptor: CLKComplicationDescriptor, completionHandler: @escaping  @Sendable (CLKComplicationWidgetMigrationConfiguration?) -> Void)
optional func widgetConfiguration(from complicationDescriptor: CLKComplicationDescriptor) async -> CLKComplicationWidgetMigrationConfiguration?

Parameters

  • complicationDescriptor:

    A descriptor that identifies a ClockKit complication.

  • completionHandler:

    A completion handler that your implementation calls after you create a configuration object that defines the WidgetKit replacement.

Discussion

Implement this method to provide the best WidgetKit configuration for the given complication descriptor. Your implementation examines the complication descriptor, then creates a configuration object and passes it to the completion handler.

func getWidgetConfiguration(from complicationDescriptor: CLKComplicationDescriptor, completionHandler: @escaping (CLKComplicationWidgetMigrationConfiguration?) -> Void) {
    
    var configuration: CLKComplicationWidgetMigrationConfiguration? = nil
    
    switch complicationDescriptor.identifier {
    case caffeineDoseIdentifier:
        configuration = CLKComplicationStaticWidgetMigrationConfiguration(
            kind: "Caffeine_Complications",
            extensionBundleIdentifier: "com.example.apple-samplecode.Coffee-Tracker.watchkitapp.watchkitextension.CoffeeTracker-Complications")
        
    case cupTotalIdentifier:
        configuration = CLKComplicationStaticWidgetMigrationConfiguration(
            kind: "CupTotal_Complications",
            extensionBundleIdentifier: "com.example.apple-samplecode.Coffee-Tracker.watchkitapp.watchkitextension.CoffeeTracker-Complications")
        
    case cupAndCaffeineIdentifier:
        configuration = CLKComplicationStaticWidgetMigrationConfiguration(
            kind: "CupAndCaffeine_Complications",
            extensionBundleIdentifier: "com.example.apple-samplecode.Coffee-Tracker.watchkitapp.watchkitextension.CoffeeTracker-Complications")
        
    default:
        configuration = nil
    }
    
    completionHandler(configuration)
    
}

For more information, see Migrating ClockKit complications to WidgetKit.