那么经过讲解,我们来看一看怎么实现数据的传输
首先我们先在最后面加入一个帮助函数
private func templateForWatch() ->CLKComplicationTemplate{
let template = CLKComplicationTemplateModularLargeStandardBody()
template.headerImageProvider = CLKImageProvider(onePieceImage: UIImage(named: "x2")!)
template.headerTextProvider = CLKSimpleTextProvider(text: "TitleHello")
template.body1TextProvider = CLKSimpleTextProvider(text: "HelloWorld, the content is not blank any more")
return template
}
如果不明觉厉的话请看我的 上一篇Blog
里面的
template.headerTextProvider = CLKSimpleTextProvider(text: "TitleHello")
template.body1TextProvider = CLKSimpleTextProvider(text: "HelloWorld, the content is not blank any more")
可以在text:后面传值,只要传的是一个字符串(String)即可
那么完成了这个函数后我们找到getCurrentTimelineEntryForComplication这个函数
往里面加入以下代码
let entries = CLKComplicationTimelineEntry(date: NSDate(), complicationTemplate: templateForWatch())
handler(entries)
这是什么呢?
我们首先构造一个CLKCompliactionTimelineEntry常量,包含一个NSDate和一个Template(也就是我们的templateForWatch返回的Template)
然后把这个常量传给handler
大功告成!
PS:因为这个Complication目前没有任何的在时间改变时改变内容的操作,我们可以在getSupportedTimeTravelDirectionsForComplication函数中这样写
func getSupportedTimeTravelDirectionsForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTimeTravelDirections) -> Void) {
handler([.None])
}
这样的话就不支持timeTravel啦