问题描述
示例:超大表盘
在 ComplicationController.swift
的 getLocalizableSampleTemplate
和 getCurrentTimelineEntry
方法中,当为超大打开 handler(nil)
时,我只传入一个 complication.family
:
case .extraLarge:
handler(nil)
但那一定不是正确的或所有要做的事情,因为我的超大并发症仍然可以选择:
但它显然不起作用或没有任何数据可显示:
有人知道我错过了什么吗?谢谢!
更新:
我的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)
}
此示例将仅显示 circularSmall
和 graphicBezel
并发症中的并发症。如果您想支持所有复杂功能,请使用 .allCases
。
如果您使用具有 AppDelegate
生命周期的 watchKit 构建您的应用程序,那么您可以在 WatchKit 扩展的 .plist 文件中定义您支持的复杂功能。您应该会看到“ClockKit Complication - Supported Families”,然后您可以添加或删除所需的复杂功能支持。