尚未为Watch App安装并发症吗?

问题描述 投票:0回答:1

我正在尝试向Watch应用程序(使用Swift UI构建)添加复杂性,但是当我在iPhone的Watch应用程序中选择“并发症”时,Watch应用程序尚未显示任何复杂性。

我创建了一个“ ComplicationController”,并为“ CircularSmall”和“ ModularLarge”并发症添加了必要的代码。下面是代码

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

        if complication.family == .circularSmall
        {

            let template = CLKComplicationTemplateCircularSmallRingText()
            template.textProvider = CLKSimpleTextProvider(text: "12")
            let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
            handler(timelineEntry)

        } else if complication.family == .modularLarge {
            let template = CLKComplicationTemplateModularLargeStandardBody()
            template.headerTextProvider = CLKSimpleTextProvider(text: "Main Header")
            template.body2TextProvider = CLKSimpleTextProvider(text: "Main complication")
            template.body1TextProvider = CLKSimpleTextProvider(text: "Sub complication 1")
            let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
            handler(timelineEntry)

        } else {

            handler(nil)
        }
    }

    func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void)
    {
        switch complication.family
        {
        case .circularSmall:
            let template = CLKComplicationTemplateCircularSmallRingText()
            template.textProvider = CLKSimpleTextProvider(text: "12")

            handler(template)
        case .modularLarge:
            let template = CLKComplicationTemplateModularLargeStandardBody()
            template.headerTextProvider = CLKSimpleTextProvider(text: "Dummy Header")
            template.body2TextProvider = CLKSimpleTextProvider(text: "Dummy Body")
            template.body1TextProvider = CLKSimpleTextProvider(text: "Dummy Body 1")

            handler(template)
        default:
            handler(nil)
        }
    }

}

我正在使用Xcode版本11.4(11E146)和Watch OS 6在Xcode中附加“并发症配置设置”的屏幕截图。

Complication Configuration in Xcode

Watch App Complication section screenshot

ios swift swiftui watchkit apple-watch-complication
1个回答
0
投票

您的代码看起来不错(我没有尝试运行它,但是写了一些静态和动态并发症)。首先安装并发症模板,然后将其缓存。如果您第一次运行应用程序时没有遇到任何麻烦,或者遇到了复杂的问题,那么新的安装覆盖图将不会将其刷新为新版本。这是练习:

  1. 在设备(手表)或模拟器上,删除应用程序
  2. 在Xcode中,清理构建文件夹
  3. 如果用于sim卡,则重建并运行复杂方案
  4. 如果是设备,则重建并运行std watch方案
  5. 除非正在测试通知,否则不要使用通知方案
  6. 根据您当前的TimelineEntry调用,您可能需要换成另一张脸,然后换回来并用复杂的方法重新自定义

祝你好运

© www.soinside.com 2019 - 2024. All rights reserved.