Complication Family support- don't show Complication Family if not supported
Asked Answered
P

1

6

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()
        }
    }
}

}

Pewit answered 20/12, 2020 at 0:7 Comment(0)
I
10

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

Incrust answered 23/12, 2020 at 19:34 Comment(4)
(Giving you the bounty because your answer makes sense and I appreciate the answer)Pewit
Thank you very much! I'm happy I could help.Fortney
oooofff finally.... hard to find the plist thing on the web to support older watchos versions... Thank you!Heidyheifer
Thank you!! I am the last Objective C programmer. I have been struggling with updating to WatchOS9 and none of my complications were appearing. The plist!!! Of course.Miyamoto

© 2022 - 2024 — McMap. All rights reserved.