ComplicationFamily支持-如果不支持,请不要显示ComplicationFamily

我想知道如果我不支持它,如何不显示复杂功能系列。

示例:超大表盘

ComplicationController.swift'sgetLocalizableSampleTemplategetCurrentTimelineEntry方法中,我只在handler(nil)打开complication.familyExtra Large时传入 a :

 case .extraLarge:
     handler(nil)

但这一定不是正确的或所有要做的,因为我的 Extra Large 并发症仍然可以选择:

但它显然不起作用或有任何数据可显示:

有谁知道我错过了什么?谢谢!

更新:

ComplicationController.swiftgetComplicationDescriptors

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

这也是我WatchApp.swift使用 SwiftUI 生命周期的(除非我弄错了):

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

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

}

回答

如果您使用 SwiftUI 生命周期构建 watchOS 应用程序,则可以使用该getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void)方法设置支持的复杂功能。

要仅支持某些复杂性,您可以定义要在数组中支持的复杂性:

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

这个例子只会在circularSmallgraphicBezel并发症中显示你的并发症。如果您想支持所有并发症,请使用.allCases.

如果您使用带有AppDelegate生命周期的 watchKit 构建您的应用程序,那么您可以在 WatchKit 扩展的 .plist 文件中定义您支持的复杂功能。您应该会看到“ClockKit Complication - Supported Families”,然后您可以添加或删除所需的复杂功能支持。


以上是ComplicationFamily支持-如果不支持,请不要显示ComplicationFamily的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>