【问题标题】:Complication Family support- don't show Complication Family if not supported并发症系列支持 - 如果不支持,则不显示并发症系列
【发布时间】:2020-12-20 00:07:54
【问题描述】:

如果我不支持,我想知道如何不显示并发症族。

示例:超大表盘

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

 case .extraLarge:
     handler(nil)

但这一定不是对的,也不一定是这样,因为我的特大号并发症仍然可以选择:

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

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

更新:

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

}

【问题讨论】:

    标签: watchkit apple-watch watchos apple-watch-complication clockkit


    【解决方案1】:

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

    【讨论】:

    • (给你赏金,因为你的回答很有道理,我很欣赏这个答案)
    • 非常感谢!我很高兴能帮上忙。
    • ooooff 终于....很难在网络上找到支持旧版 watchos 的 plist 东西...谢谢!
    猜你喜欢
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多