-
-
Save lgv2800/b1e16fbc3774c430aab3b3954d394068 to your computer and use it in GitHub Desktop.
ConfigurationIntent dosen’t load dynamic objects - stuck at loading indicator - iOS 14.2
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 { | |
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 | |
} | |
} | |
extension IntentHandler: SelectSavingGoalIntentHandling { | |
func provideSavingGoalOptionsCollection( | |
for intent: SelectSavingGoalIntent, | |
with completion: @escaping (INObjectCollection<SavingGoalINO>?, Error?) -> Void | |
) { | |
var savingGoalItems = [SavingGoalINO]() | |
DataManager.shared.getSavingGoals(filter: Filter.all).forEach { savingGoal in | |
let savingGoalIntentObject = SavingGoalINO(identifier: savingGoal.id?.uuidString, display: savingGoal.savingTitle ?? "Saving goal") | |
savingGoalItems.append(savingGoalIntentObject) | |
} | |
completion(INObjectCollection(items: savingGoalItems), nil) | |
} | |
} |
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 SwiftUI | |
import WidgetKit | |
struct SavingGoalEntry: TimelineEntry { | |
let id: UUID? | |
var date: Date | |
//let configuration: ConfigurationIntent | |
let savingGoal: SavingGoal | |
} |
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 SwiftUI | |
import WidgetKit | |
struct SavingGoalWidgetProvider: IntentTimelineProvider { | |
typealias Entry = SavingGoalEntry | |
typealias Intent = SelectSavingGoalIntent | |
func placeholder(in context: Context) -> SavingGoalEntry { | |
var savingGoalPlaceholder = SavingGoal(context: CoreDataManager.shared.getManagedObjectContext()) | |
savingGoalPlaceholder.savingTitle = "Placeholder title" | |
savingGoalPlaceholder.savingHasTargetAmount = true | |
savingGoalPlaceholder.savingTargetAmount = 1000 | |
savingGoalPlaceholder.savingSavedAmount = 500 | |
return SavingGoalEntry(id: UUID(), date: Date(), savingGoal: savingGoalPlaceholder) | |
} | |
func getSnapshot(for configuration: SelectSavingGoalIntent, in context: Context, completion: @escaping (SavingGoalEntry) -> ()) { | |
// let snapshotSavingGoal = DataManager.shared.getSavingGoal(savingGoalUUID: UUID(uuidString: configuration.savingGoal?.identifier ?? "") ?? UUID()) | |
let snapshotSavingGoal = lookupSavingGoalDetails(for: configuration) | |
let entry = SavingGoalEntry(id: UUID(), date: Date(), savingGoal: snapshotSavingGoal) | |
completion(entry) | |
} | |
func getTimeline(for configuration: SelectSavingGoalIntent, in context: Context, completion: @escaping (Timeline<SavingGoalEntry>) -> ()) { | |
var entries = [SavingGoalEntry]() | |
let savingDetails = lookupSavingGoalDetails(for: configuration) | |
let entry = SavingGoalEntry(id: UUID(), date: Date(), savingGoal: savingDetails) | |
entries.append(entry) | |
let timeline = Timeline(entries: entries, policy: .never) | |
completion(timeline) | |
} | |
private func lookupSavingGoalDetails(for configuration: SelectSavingGoalIntent) -> SavingGoal { | |
guard let savingGoalId = configuration.savingGoal?.identifier, | |
let savingForConfig = DataManager.shared.getSavingGoals(filter: Filter.all).first(where: { savingGoal in | |
savingGoal.id?.uuidString == savingGoalId | |
}) | |
else { | |
return DataManager.shared.getSavingGoals(filter: Filter.all).first! | |
//return DataManager.shared.getSavingGoals(filter: Filter.all).first ?? SavingGoal(context: CoreDataManager.shared.getManagedObjectContext()) | |
} | |
return savingForConfig | |
} | |
} | |
struct SavingGoalWidgetEntryView: View { | |
var entry: SavingGoalWidgetProvider.Entry | |
var body: some View { | |
Savings_WidgetEntryView(entry: entry) | |
} | |
} | |
@main | |
struct SavingGoalWidget: Widget { | |
private let kind: String = "SavingGoalWidget" | |
public var body: some WidgetConfiguration { | |
IntentConfiguration( | |
kind: kind, | |
intent: SelectSavingGoalIntent.self, | |
provider: SavingGoalWidgetProvider() | |
) { entry in | |
SavingGoalWidgetEntryView(entry: entry) | |
} | |
.configurationDisplayName("Savings Widget") | |
.description("Display a widget with a Saving of your choice.") | |
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment