WatchKit 2并发症文本仅在预览中显示 [英] WatchKit 2 Complication Text Only Shows Up in Preview
问题描述
我正在尝试为 watchkit的情况开发一种非常简单的功能 2从简单的文本提供程序中说嗨".
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()
}
我的得到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)
}
}
推荐答案
在自定义表盘时,Apple Watches会调用getPlaceholderTemplateForComplication:withHandler:
来显示占位符文本.既然实现了,就可以看到嗨".太棒了.
但是当表盘显示出来时,它会调用其他方法,例如:
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:
getCurrentTimelineEntryForComplication:withHandler:
getTimelineEntriesForComplication:beforeDate:limit:withHandler:
getTimelineEntriesForComplication:afterDate:limit:withHandler:
似乎您没有实现它们.因此,实施这些方法将解决您的问题. 您可以在此WWDC 2015教程中找到有关这些方法的更多详细信息: https://developer.apple.com/videos/wwdc/2015/?id=209
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
这篇关于WatchKit 2并发症文本仅在预览中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!