1

我正在尝试为 2 开发一个非常简单的复杂功能,它从一个简单的文本提供程序中说“嗨”。

我设法实现了一些奇怪的行为;单击复杂功能或从自定义表盘屏幕预览时,我可以看到文本,但在显示表盘时看不到。看一看:

表盘表现异常 gif

有什么想法可能导致这种情况吗?

我的文本提供程序看起来像这样

var textProvider: CLKSimpleTextProvider

override init() {

    textProvider = CLKSimpleTextProvider()
    textProvider.text = "Hi"
    textProvider.shortText = "HI"
    textProvider.tintColor = UIColor.whiteColor()
    super.init()
}

我的得到getPlaceholderTemplateForComplication看起来像

func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
    // This method will be called once per supported complication, and the results will be cached

     switch complication.family {
     case .ModularSmall:
        let stemplate = CLKComplicationTemplateModularSmallSimpleText()
        stemplate.tintColor = UIColor.whiteColor()
        stemplate.textProvider = textProvider
        handler(stemplate)
     case .CircularSmall:
        let stemplate = CLKComplicationTemplateCircularSmallSimpleText()
        stemplate.tintColor = UIColor.whiteColor()
        stemplate.textProvider = textProvider
        handler(stemplate)
     default:
        handler(nil)
    }

}
4

1 回答 1

3

在自定义表盘时,Apple Watch 会调用getPlaceholderTemplateForComplication:withHandler:以显示占位符文本。既然你已经实现了它 - 你可以看到“嗨”。太棒了。但是当表盘显示时,它会调用另一个方法,例如:

  • getCurrentTimelineEntryForComplication:withHandler:
  • getTimelineEntriesForComplication:beforeDate:limit:withHandler:
  • getTimelineEntriesForComplication:afterDate:limit:withHandler:

似乎您没有实施它们。因此,实施这些方法将解决您的问题。您可以在此 WWDC 2015 教程中找到有关这些方法的更多详细信息:https ://developer.apple.com/videos/wwdc/2015/?id=209

于 2015-09-24T23:43:24.090 回答