WatchKit 2 Complication Text Only Shows Up in Prev

2020-04-18 06:47发布

I'm trying to develop a very simple complication for 2 that says "Hi" from a simple text provider.

I've managed to achieve some strange behavior; I can see the text when the complication is clicked or when you are previewing it from the customize watchface screen, but not when the watchface is displayed. Have a look:

watchface behaviing strangely gif

Any ideas what might be causing this?

My text provider looks like this

var textProvider: CLKSimpleTextProvider

override init() {

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

And my get getPlaceholderTemplateForComplication looks like

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

}

1条回答
何必那么认真
2楼-- · 2020-04-18 07:37

While customizing watch face, Apple Watches calls getPlaceholderTemplateForComplication:withHandler: to show placeholder text. Since you've implemented it - you can see "Hi". That is cool. But when watch face displayed, it calls another methods, such as:

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

And it seems like you're not implemented them. So implementing these method will resolve your issue. You can find more detailed information about these methods in this WWDC 2015 Tutorial: https://developer.apple.com/videos/wwdc/2015/?id=209

查看更多
登录 后发表回答