Created
August 8, 2022 12:32
-
-
Save elnino-ict/9ff98c6741716fe9baf488aedcb1400b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Intents | |
class IntentHandler: INExtension, ConfigurationBuggyIntentHandling { | |
func provideDynamicmeOptionsCollection(for intent: ConfigurationBuggyIntent, with completion: @escaping (INObjectCollection<DynamicType>?, Error?) -> Swift.Void) { | |
let collection = INObjectCollection(items: [ | |
DynamicType(identifier: "123", display: "first"), | |
DynamicType(identifier: "124", display: "second"), | |
DynamicType(identifier: "125", display: "third"), | |
DynamicType(identifier: "126", display: "fourth"), | |
DynamicType(identifier: "127", display: "fifth"), | |
]) | |
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { | |
completion(collection, nil) | |
} | |
} | |
override func handler(for intent: INIntent) -> Any { | |
// This is the default implementation. If you want different objects to handle different intents, | |
// you can override this and return the handler you want for that particular intent. | |
return self | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WidgetKit | |
import SwiftUI | |
import Intents | |
struct Provider: IntentTimelineProvider { | |
func placeholder(in context: Context) -> SimpleEntry { | |
SimpleEntry(date: Date(), configuration: ConfigurationBuggyIntent()) | |
} | |
func getSnapshot(for configuration: ConfigurationBuggyIntent , in context: Context, completion: @escaping (SimpleEntry) -> ()) { | |
let entry = SimpleEntry(date: Date(), configuration: configuration) | |
completion(entry) | |
} | |
func getTimeline(for configuration: ConfigurationBuggyIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { | |
var entries: [SimpleEntry] = [] | |
// Generate a timeline consisting of five entries an hour apart, starting from the current date. | |
let currentDate = Date() | |
for hourOffset in 0 ..< 5 { | |
let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! | |
let entry = SimpleEntry(date: entryDate, configuration: configuration) | |
entries.append(entry) | |
} | |
let timeline = Timeline(entries: entries, policy: .atEnd) | |
completion(timeline) | |
} | |
} | |
struct SimpleEntry: TimelineEntry { | |
let date: Date | |
let configuration: ConfigurationBuggyIntent | |
} | |
struct buggyEntryView : View { | |
var entry: Provider.Entry | |
var body: some View { | |
Text(entry.date, style: .time) | |
} | |
} | |
@main | |
struct buggy: Widget { | |
let kind: String = "buggy" | |
var body: some WidgetConfiguration { | |
IntentConfiguration(kind: kind, intent: ConfigurationBuggyIntent.self, provider: Provider()) { entry in | |
buggyEntryView(entry: entry) | |
} | |
.configurationDisplayName("My Widget") | |
.description("This is an example widget.") | |
} | |
} | |
struct buggy_Previews: PreviewProvider { | |
static var previews: some View { | |
buggyEntryView(entry: SimpleEntry(date: Date(), configuration: ConfigurationBuggyIntent())) | |
.previewContext(WidgetPreviewContext(family: .systemSmall)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment