1

I have followed the Apple Developer guide on setting up my ComplicationController. I have set modularLarge enabled, and made sure its also enabled in info.plist.

I have set my data source in Complication Settings to "$(PRODUCT_MODULE_NAME).ComplicationController" which cross checks with info.plist.

I can select the Complication on the watch but it doesn't load any of the Test labels. It just says:

My App Name

"- - - - - - - -"

"- - - - - - - -"

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

}

screenshot of info plist screenshot of complications configuration

4

1 回答 1

1

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

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

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

于 2020-07-17T07:22:56.553 回答