WatchKit 2 Complication Text Only Shows Up in Preview

旧时模样 提交于 2019-12-02 07:18:56

问题


I'm trying to develop a very simple complication for watchkit2 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:

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:


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



来源:https://stackoverflow.com/questions/32443304/watchkit-2-complication-text-only-shows-up-in-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!