Search code examples
watchkitapple-watchwatchosapple-watch-complicationclockkit

Complication Family support- don't show Complication Family if not supported


I'm wondering how to not show a Complication Family if I'm not supporting it.

Example: Extra Large watch face

In ComplicationController.swift's getLocalizableSampleTemplate and getCurrentTimelineEntry methods I just pass in a handler(nil) when switching on complication.family for Extra Large:

 case .extraLarge:
     handler(nil)

But that must not be right or all there is to do, because my complication for Extra Large is still able to be chosen:

enter image description here

But it obviously doesn't work or have any data to show:

enter image description here

Does anyone know what I'm missing? Thanks!

UPDATE:

My ComplicationController.swift's getComplicationDescriptors:

    func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) {
    
    let oneSupported = [
        CLKComplicationFamily.circularSmall,
        .modularSmall,
        .utilitarianSmall,
        .modularLarge,
        .utilitarianLarge,
        .graphicExtraLarge,
        .graphicCircular
    ]
    
    let twoSupported = [
        CLKComplicationFamily.circularSmall,
        .modularSmall,
        .utilitarianSmall,
        .utilitarianSmallFlat,
        .extraLarge,
        .graphicBezel,
        .graphicCircular,
        .graphicCorner,
        .graphicRectangular,
        .modularLarge,
        .utilitarianLarge
    ]
    
    let descriptors = [
        CLKComplicationDescriptor(identifier: ComplicationIdentifier.height.rawValue, displayName: "Complication 1", supportedFamilies: oneSupported)
        // Multiple complication support can be added here with more descriptors
        ,
        CLKComplicationDescriptor(identifier: ComplicationIdentifier.price.rawValue, displayName: "Complication 2", supportedFamilies: twoSupported)
    ]
    
    // Call the handler with the currently supported complication descriptors
    handler(descriptors)
}

Also here's my WatchApp.swift which is using that SwiftUI lifecycle (unless I'm mistaken):

struct BlockWatchApp: App {
@WKExtensionDelegateAdaptor(ExtensionDelegate.self) var extensionDelegate

var body: some Scene {
    WindowGroup {
        NavigationView {
            WatchView()
        }
    }
}

}


Solution

  • If you're building your watchOS App using the SwiftUI lifecycle you set up your supported complications using the getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) method.

    To support only certain complications you define which ones you want to support in an array:

    func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) {
        let descriptors = [
            CLKComplicationDescriptor(identifier: "complication", displayName: "App Name",
                                      supportedFamilies: [CLKComplicationFamily.circularSmall,
                                                          CLKComplicationFamily.graphicBezel])
            // Multiple complication support can be added here with more descriptors/
            // Create a new identifier for each new CLKComplicationDescriptor.
        ]
        // Call the handler with the currently supported complication descriptors
        handler(descriptors)
    }
    

    This example will only display your complication in the circularSmall and graphicBezel complications. If you want to support all complications use .allCases.

    If you're building your App using the watchKit with AppDelegate lifecycle then you define your supported complications in the .plist file in the WatchKit Extension. You should see "ClockKit Complication - Supported Families" then you can add or delete your desired complication support.

    .plistImage