I am trying to add complication to watch app (built using Swift UI) but when I select the "Complications" in the Watch app in iPhone it is showing no complications installed on the Watch app yet.
I have created a "ComplicationController" and added necessary code for "CircularSmall" and "ModularLarge" complication. Below is the code
class ComplicationController: NSObject, CLKComplicationDataSource {
func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
handler([])
}
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
if complication.family == .circularSmall
{
let template = CLKComplicationTemplateCircularSmallRingText()
template.textProvider = CLKSimpleTextProvider(text: "12")
let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
handler(timelineEntry)
} else if complication.family == .modularLarge {
let template = CLKComplicationTemplateModularLargeStandardBody()
template.headerTextProvider = CLKSimpleTextProvider(text: "Main Header")
template.body2TextProvider = CLKSimpleTextProvider(text: "Main complication")
template.body1TextProvider = CLKSimpleTextProvider(text: "Sub complication 1")
let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
handler(timelineEntry)
} else {
handler(nil)
}
}
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void)
{
switch complication.family
{
case .circularSmall:
let template = CLKComplicationTemplateCircularSmallRingText()
template.textProvider = CLKSimpleTextProvider(text: "12")
handler(template)
case .modularLarge:
let template = CLKComplicationTemplateModularLargeStandardBody()
template.headerTextProvider = CLKSimpleTextProvider(text: "Dummy Header")
template.body2TextProvider = CLKSimpleTextProvider(text: "Dummy Body")
template.body1TextProvider = CLKSimpleTextProvider(text: "Dummy Body 1")
handler(template)
default:
handler(nil)
}
}
}
I am using Xcode Version 11.4 (11E146) & Watch OS 6 Attaching screenshots of the Complication Configuration Settings in Xcode.

