如何解决Complication Family 支持 - 如果不支持,请不要显示 Complication Family
如果我不支持复杂功能系列,我想知道如何不展示它。
示例:超大表盘
在 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”,然后您可以添加或删除所需的复杂功能支持。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。