Ios 检测Text.DateStyle.timer何时达到00:00

Ios 检测Text.DateStyle.timer何时达到00:00,ios,swift,swiftui,widgetkit,Ios,Swift,Swiftui,Widgetkit,因此,我对WidgetKit和SwiftUI还不熟悉,但是对于Text(),是否有一个事件或方法可以检测倒计时何时达到00:00 似乎它要么记录得很差——至少对我来说——要么仍然没有这样的记录。这是不可能的,当它达到0时,它将开始计数 您必须使用时间线在倒计时结束日期刷新该小部件,使用仅显示0:00:00的普通文本 例如: var entries: [SingleEntry] = [] // First entry at Date() which is now..

因此,我对WidgetKit和SwiftUI还不熟悉,但是对于Text(),是否有一个事件或方法可以检测倒计时何时达到00:00


似乎它要么记录得很差——至少对我来说——要么仍然没有这样的记录。

这是不可能的,当它达到0时,它将开始计数

您必须使用时间线在倒计时结束日期刷新该小部件,使用仅显示0:00:00的普通文本

例如:

var entries: [SingleEntry] = []
                // First entry at Date() which is now... with the countdown endDate at 60 seconds in the future
                // which you'll use in the Text(date, style)
                entries.append(
                    SingleEntry(
                        date: Date(),
                        configuration: configuration,
                        endDate: Date().addingTimeInterval(60)
                    )
                )
                
                // Second entry which will be scheduled at the Date when you want to stop the timer
                // in the TimelineEntry now you can check if endDate is nil and use a normale text
                // to say that the countdown is over
                entries.append(
                    SingleEntry(
                        date: Date().addingTimeInterval(60),
                        configuration: configuration,
                        endDate: nil
                    )
                )
                
                let timeline = Timeline(entries: entries, policy: .atEnd)
                completion(timeline)


什么倒计时?@JoakimDanielson。计时器倒计时,刚刚编辑。这回答了你的问题吗?@Asperi似乎不与WidgetKitI合作。我已经有了一个一整天相隔5分钟的时间表。。如何在这些条目之间添加签入。此外,小部件似乎不会在给定的时间内完全更新date@Sayed检查编辑后的答案,这就是开始和停止倒计时所需的全部内容,如果每隔5分钟必须执行其他操作,只需在结束日期之前创建更多条目,并相应地设置更新的小部件
var entries: [SingleEntry] = []
                // First entry at Date() which is now... with the countdown endDate at 60 seconds in the future
                // which you'll use in the Text(date, style)
                entries.append(
                    SingleEntry(
                        date: Date(),
                        configuration: configuration,
                        endDate: Date().addingTimeInterval(60)
                    )
                )
                
                // Second entry which will be scheduled at the Date when you want to stop the timer
                // in the TimelineEntry now you can check if endDate is nil and use a normale text
                // to say that the countdown is over
                entries.append(
                    SingleEntry(
                        date: Date().addingTimeInterval(60),
                        configuration: configuration,
                        endDate: nil
                    )
                )
                
                let timeline = Timeline(entries: entries, policy: .atEnd)
                completion(timeline)