有没有使用 localizableTextProvider(withStringsFileFormatKey:, textProviders:) 设置复杂功能的官方示例?我可以在生成 SampleTemplate 时填充文本提供程序,但是每当我尝试使用 getTimelineEntries 生成模板时,由 localizableTextProvider 生成的文本提供程序结果总是空白,没有文本。
示例(仅支持 .utilitarianLarge):
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
// Call the handler with the current timeline entry
let template = CLKComplicationTemplateUtilitarianLargeFlat()
template.textProvider = CLKTextProvider.localizableTextProvider(
withStringsFileFormatKey: "testComplication",
textProviders: [
CLKSimpleTextProvider(text: "Hello"),
CLKSimpleTextProvider(text: "World")
]
)
handler(CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template))
}
和 sampleTemplate 作为
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
switch complication.family {
case .utilitarianLarge:
let template = CLKComplicationTemplateUtilitarianLargeFlat()
template.textProvider = CLKTextProvider.localizableTextProvider(
withStringsFileFormatKey: "testComplication",
textProviders: [
CLKSimpleTextProvider(text: "Hi"),
CLKSimpleTextProvider(text: "World")
]
)
handler(template)
default:
handler(nil)
}
}
与 ckcomplication.strings 作为
"testComplication" = "%@ %@";
示例模板将始终显示文本“Hi World”,而 getCurrentTimelineEntry 的结果将始终显示一个空的复杂功能。
有没有人有幸以这种方式编写文本提供程序?