Complication Family 支持 - 如果不支持,请不要显示 Complication Family

问题描述

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

示例:超大表盘

ComplicationController.swiftgetLocalizableSampleTemplategetCurrentTimelineEntry 方法中,当为超大打开 handler(nil) 时,我只传入一个 complication.family

 case .extraLarge:
     handler(nil)

但那一定不是正确的或所有要做的事情,因为我的超大并发症仍然可以选择:

enter image description here

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

enter image description here

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

更新:

我的ComplicationController.swift的{​​{1}}:

getComplicationDescriptors

还有我的 func getComplicationDescriptors(handler: @escaping ([CLKComplicationDescriptor]) -> Void) { let onesupported = [ CLKComplicationFamily.circularSmall,.modularsmall,.utilitarianSmall,.modularLarge,.utilitarianLarge,.graphicExtraLarge,.graphicCircular ] let twoSupported = [ CLKComplicationFamily.circularSmall,.utilitarianSmallFlat,.extraLarge,.graphicBezel,.graphicCircular,.graphicCorner,.graphicRectangular,.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) } ,它使用了 SwiftUI 生命周期(除非我弄错了):

WatchApp.swift

}

解决方法

如果您使用 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”,然后您可以添加或删除所需的复杂功能支持。

.plistImage

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...