Apple Watch 上的并发症不显示我的信息
Complication on Apple Watch not showing my information
我在 Apple Watch 上遇到了并发症问题。
我正在尝试在复杂功能上显示图像和一些文本。我可以 select 时钟界面上的复杂功能,但它没有显示应用程序标题和两行充满“-”字符的内容。
并发症应该显示我的信息,但我没有看到我的代码有什么问题
代码如下:
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
handler(nil)
var template: CLKComplicationTemplateModularLargeColumns?
switch complication.family {
case .modularSmall:
template = nil
case .modularLarge:
let modularLargeTemplate =
CLKComplicationTemplateModularLargeColumns()
modularLargeTemplate.row1ImageProvider =
CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
modularLargeTemplate.row2ImageProvider =
CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
modularLargeTemplate.row3ImageProvider =
CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
modularLargeTemplate.row1Column1TextProvider = CLKSimpleTextProvider(text: "User: ")
modularLargeTemplate.row1Column2TextProvider = CLKSimpleTextProvider(text: "ok")
modularLargeTemplate.row2Column1TextProvider = CLKSimpleTextProvider(text: "Car: ")
modularLargeTemplate.row2Column2TextProvider = CLKSimpleTextProvider(text: "ok")
modularLargeTemplate.row3Column1TextProvider = CLKSimpleTextProvider(text: "Environment: ")
modularLargeTemplate.row3Column2TextProvider = CLKSimpleTextProvider(text: "ok")
template = modularLargeTemplate
case .utilitarianSmall:
template = nil
case .utilitarianLarge:
template = nil
case .circularSmall:
template = nil
default:
template = nil
}
handler(template)
}
如果我在代码中间放置一个断点,调试器会触发它,所以它会执行这段代码。但是没有任何显示如我所愿。
你能找到什么是 wrong/missing 吗?
这只是模板,您需要注意 getCurrentTimelineEntry
,最简单的方法就是 return 与模板相同的条目(见下文)。
正如评论中提到的其他人一样,您还需要删除代码中的 handler(nil)
。
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
getLocalizableSampleTemplate(for: complication) {template in
guard let template = template else {
handler(nil)
return
}
handler(CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template))
}
}
我在 Apple Watch 上遇到了并发症问题。
我正在尝试在复杂功能上显示图像和一些文本。我可以 select 时钟界面上的复杂功能,但它没有显示应用程序标题和两行充满“-”字符的内容。
并发症应该显示我的信息,但我没有看到我的代码有什么问题
代码如下:
func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {
// This method will be called once per supported complication, and the results will be cached
handler(nil)
var template: CLKComplicationTemplateModularLargeColumns?
switch complication.family {
case .modularSmall:
template = nil
case .modularLarge:
let modularLargeTemplate =
CLKComplicationTemplateModularLargeColumns()
modularLargeTemplate.row1ImageProvider =
CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
modularLargeTemplate.row2ImageProvider =
CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
modularLargeTemplate.row3ImageProvider =
CLKImageProvider(onePieceImage: UIImage(named: "GreenUser")!)
modularLargeTemplate.row1Column1TextProvider = CLKSimpleTextProvider(text: "User: ")
modularLargeTemplate.row1Column2TextProvider = CLKSimpleTextProvider(text: "ok")
modularLargeTemplate.row2Column1TextProvider = CLKSimpleTextProvider(text: "Car: ")
modularLargeTemplate.row2Column2TextProvider = CLKSimpleTextProvider(text: "ok")
modularLargeTemplate.row3Column1TextProvider = CLKSimpleTextProvider(text: "Environment: ")
modularLargeTemplate.row3Column2TextProvider = CLKSimpleTextProvider(text: "ok")
template = modularLargeTemplate
case .utilitarianSmall:
template = nil
case .utilitarianLarge:
template = nil
case .circularSmall:
template = nil
default:
template = nil
}
handler(template)
}
如果我在代码中间放置一个断点,调试器会触发它,所以它会执行这段代码。但是没有任何显示如我所愿。
你能找到什么是 wrong/missing 吗?
这只是模板,您需要注意 getCurrentTimelineEntry
,最简单的方法就是 return 与模板相同的条目(见下文)。
正如评论中提到的其他人一样,您还需要删除代码中的 handler(nil)
。
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
getLocalizableSampleTemplate(for: complication) {template in
guard let template = template else {
handler(nil)
return
}
handler(CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template))
}
}