Я пытаюсь создать виджет iOS 14, который обновляется каждые две минуты. Это код виджета:
import WidgetKit
import SwiftUI
import Intents
struct SimpleEntry: TimelineEntry {
let date: Date
let configuration: ConfigurationIntent
}
struct Provider: IntentTimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date(), configuration: ConfigurationIntent())
}
func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), configuration: configuration)
completion(entry)
}
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
let entry1 = SimpleEntry(date: Date(), configuration: configuration)
let timeline = Timeline(entries: [entry1], policy: .after(Date().addingTimeInterval(2*60.0)))
print("timeline: \(timeline)")
completion(timeline)
}
}
struct TeamWidgetEntryView : View {
@Environment(\.widgetFamily) var family
var entry: Provider.Entry
@ViewBuilder
var body: some View {
switch family {
case .systemSmall:
SmallView(date: Date())
case .systemMedium:
MediumView()
case .systemLarge:
LargeView()
default:
Text("Some other WidgetFamily in the future.")
}
}
}
@main
struct TeamWidget: Widget {
let kind: String = "TeamWidget"
var body: some WidgetConfiguration {
IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in
TeamWidgetEntryView(entry: entry)
}
.configurationDisplayName("My Widget")
.description("This is an example widget.")
.supportedFamilies([.systemSmall,.systemMedium,.systemLarge])
}
}
Это класс SmallView:
struct SmallView: View {
var date: Date
static let taskDateFormat: DateFormatter = {
let formatter = DateFormatter()
formatter.timeStyle = .medium
return formatter
}()
var body: some View {
VStack {
Text("Small View")
Text("\(Date(), formatter: Self.taskDateFormat)")
}
}
}
Я хочу, чтобы виджет обновлялся каждые 2 минуты, но этого не происходит, знаете, в чем проблема?