【问题标题】:iOS Watch ComplicationController not showing resultiOS Watch ComplicationController 不显示结果
【发布时间】:2020-11-06 15:37:59
【问题描述】:

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

我已将复杂设置中的数据源设置为“$(PRODUCT_MODULE_NAME).ComplicationController”,它与 info.plist 进行交叉检查。

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

我的应用名称

“- - - - - - - -”

“- - - - - - - -”

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)
    }
}

}

【问题讨论】:

    标签: swift watchkit watch clockkit


    【解决方案1】:

    您在 getPlaceholderTemplateForComplication 中返回“Test1”等 - 正如 https://developer.apple.com/documentation/clockkit/clkcomplicationdatasource/1628026-getplaceholdertemplateforcomplic?language=objc 的文档所说的那样

    获取一个静态模板以显示在您的并发症的选择屏幕中。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多