How to display image in watchOS complication How to display image in watchOS complication swift swift

How to display image in watchOS complication


At first I strongly recommend you to watch an Apple's session about Complications unless you haven't seen it yet.

You need to implement 3 following non-optional methods of CLKComplicationDataSource in your ComplicationController at least:

public func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void)public func getCurrentTimelineEntryForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimelineEntry?) -> Void)public func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void)

All other methods are optional. As far as you see you implemented only the second one. Implementations of remaining two could be the following in your context:

class ComplicationController: NSObject, CLKComplicationDataSource {    func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) {         // Turn off time travelling        handler([CLKComplicationTimeTravelDirections.None])    }    func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {        var template: CLKComplicationTemplate?        switch complication.family {            case .CircularSmall:                template = CLKComplicationTemplateCircularSmallRingImage()                template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "app_icon")!)            case .UtilitarianSmall:                template = CLKComplicationTemplateUtilitarianSmallRingImage()                template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "app_icon")!)            case .ModularSmall:                template = CLKComplicationTemplateModularSmallRingImage()                template.imageProvider = CLKImageProvider(onePieceImage: UIImage(named: "app_icon")!)            case .ModularLarge:                template = nil            case .UtilitarianLarge:                template = nil        }        handler(template)    }}

And don't forget to specify your Data Source Class in Complication Configuration as $(PRODUCT_MODULE_NAME).ComplicationController and check appropriate checkboxes.enter image description here

That's the minimal complication configuration in your case.