Apple Watch 上的并发症未显示我的信息

A. *_*lva 5 ios swift apple-watch apple-watch-complication

我在 Apple Watch 上遇到了并发症问题。

我正在尝试在复杂功能上显示图像和一些文本。我可以在时钟界面上选择复杂功能,但它没有显示应用程序标题和两行充满“-”字符的内容。

并发症应该显示我的信息,但我没有看到我的代码有什么问题

这是代码:

func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
    // This method will be called once per supported complication, and the results will be cached
    handler(nil)
    var template: CLKComplicationTemplateModularLargeColumns?
    switch complication.family {
    case .modularSmall:
        template = nil
    case .modularLarge:
        let modularLargeTemplate =
            CLKComplicationTemplateModularLargeColumns()
        modularLargeTemplate.row1ImageProvider =
            CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
        modularLargeTemplate.row2ImageProvider =
            CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
        modularLargeTemplate.row3ImageProvider =
            CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)

        modularLargeTemplate.row1Column1TextProvider = CLKSimpleTextProvider(text: "User: ")
        modularLargeTemplate.row1Column2TextProvider = CLKSimpleTextProvider(text: "ok")

        modularLargeTemplate.row2Column1TextProvider = CLKSimpleTextProvider(text: "Car: ")
        modularLargeTemplate.row2Column2TextProvider = CLKSimpleTextProvider(text: "ok")

        modularLargeTemplate.row3Column1TextProvider = CLKSimpleTextProvider(text: "Environment: ")
        modularLargeTemplate.row3Column2TextProvider = CLKSimpleTextProvider(text: "ok")

        template = modularLargeTemplate
    case .utilitarianSmall:
        template = nil
    case .utilitarianLarge:
        template = nil
    case .circularSmall:
        template = nil
    default:
        template = nil
    }
    handler(template)

}
Run Code Online (Sandbox Code Playgroud)

如果我在代码中间放置一个断点,调试器会触发它,因此它会执行此代码。但是没有像我想要的那样显示。

你能找到什么是错的/遗漏的吗?

Voj*_*jbr 3

这只是模板,您需要注意getCurrentTimelineEntry,最简单的就是返回与模板相同的条目(见下文)。正如评论中其他人提到的,您handler(nil)也需要在代码中删除。

func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
        getLocalizableSampleTemplate(for: complication) {template in
            guard let template = template else {
                handler(nil)
                return
            }
            handler(CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template))
        }
    }
Run Code Online (Sandbox Code Playgroud)