iOS 观看 ComplicationController 未显示结果

iOS Watch ComplicationController not showing result

我已按照 Apple 开发人员指南设置我的 ComplicationController。我已启用 modularLarge,并确保它在 info.plist.

中也已启用

我在 Complication Settings 中将我的数据源设置为“$(PRODUCT_MODULE_NAME).ComplicationController”,它与 info.plist.

交叉检查

我可以 select 手表上的复杂功能,但它不会加载任何测试标签。它只是说:

我的应用名称

"- - - - - - - -"

"- - - - - - - -"

import Foundation
import WatchKit
import ClockKit

class ComplicationController: NSObject, CLKComplicationDataSource {

func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
    handler([])
}

func getCurrentTimelineEntry(for complication: CLKComplication,
                         withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {

    handler(nil)

}

func getPrivacyBehaviorForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationPrivacyBehavior) -> Void) {
    handler(.showOnLockScreen)
}

func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
    switch complication.family {
    case .modularLarge:
        let template = CLKComplicationTemplateModularLargeStandardBody()
        
        template.headerTextProvider = CLKSimpleTextProvider(text: "Test1", shortText: "T1")
        template.body1TextProvider = CLKSimpleTextProvider(text: "Test2", shortText: nil)
        template.body2TextProvider = CLKSimpleTextProvider(text: "Test2", shortText: nil)
        
        handler(template)
    default:
        handler(nil)
    }
}

}

您在 getPlaceholderTemplateForComplication 中 returning "Test1" 等 - 正如 https://developer.apple.com/documentation/clockkit/clkcomplicationdatasource/1628026-getplaceholdertemplateforcomplic?language=objc 的文档所述

Gets a static template to display in the selection screen for your complication.

您需要使用 getCurrentTimelineEntry(...) 来return复杂功能上显示的实际数据。