Как упомянуто @ Paulw11, вы должны предоставить график времени для осложнения. Вы можете сделать это в Methode «getTimelineEntries» в классе «ComplicationController»:
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries after to the given date
var entries = [CLKComplicationTimelineEntry]()
for i in 0...(limit) {
var futureDate = date
futureDate.addTimeInterval(TimeInterval(60 * i))
switch complication.family {
case .utilitarianLarge:
let template = CLKComplicationTemplateUtilitarianLargeFlat()
let currentDateTime = Date()
let formatter = DateFormatter()
formatter.dateFormat = "h:mm a"
let dateTimeString = formatter.string(from: futureDate)
let timeLineText = dateTimeString
template.textProvider = CLKSimpleTextProvider(text: "\(timeLineText)")
let timelineEntry = CLKComplicationTimelineEntry(date: futureDate, complicationTemplate: template)
entries.append(timelineEntry)
default:
handler(nil)
}
}
handler(entries)
}
}
Для обновления временной шкалы сложности вы можете использовать метод CLKComplicationServer.sharedInstance().extendTimeline()
или CLKComplicationServer.sharedInstance().reloadTimeline()
.
Вы можете попытаться вызвать их в задании BackgroundAppRefre sh. Я пытаюсь сделать то же самое, что и вы, в момент (создайте усложнение, которое в моем случае показывает время в виде строки "ЧЧ: ММ"), но BackgroundAppRefre sh работает, только если AppleWatch находится в той же беспроводной сети, что и iPhone. Если у кого-то есть идеи, как решить эту проблему, я был бы очень благодарен!