I’m developing an iOS app with Swift 5.9, SwiftUI, Xcode 15.3 and Firebase. My deployment target is iOS 17. I’ve faced a problem when creating a new configurable widget using WidgetConfigurationIntent.
The widget is using Firebase Authentication and Firestore to download user’s documents (“Deck”) and display them as a list of values in widget’s configuration.
When I’m running my widget in a simulator (also using my device as a run destination), the widget works fine. But when I run it on device (without running from Xcode), the list of values doesn’t open. I know that dynamic list was successfully fetched because the first item from the fetched array was chosen as a default parameter.
I’m new at programming so I’d be grateful if someone can help me.
struct SelectDeckAppIntent: WidgetConfigurationIntent {
static var title: LocalizedStringResource = "Select deck"
static var description = IntentDescription("Select a deck to display information for.")
@Parameter(title: "Deck")
var deck: DeckEntity
}
struct DeckEntity: AppEntity {
let id: String
let title: String
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Deck"
static var defaultQuery = DeckQuery()
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: "(title)")
}
static func getAllDecks() async throws -> [DeckEntity] {
guard let userID = Auth.auth().currentUser?.uid else {
throw NSError(domain: "AppError", code: 0, userInfo: [NSLocalizedDescriptionKey: "Authentication failed or user not logged in"])
}
let db = Firestore.firestore()
let ref = db.collection("users").document(userID).collection("decks")
let snapshot = try await ref.getDocuments()
return snapshot.documents.compactMap { document -> DeckEntity? in
guard let title = document.data()["title"] as? String else {
return nil
}
return DeckEntity(id: document.documentID, title: title)
}
}
}
struct DeckQuery: EntityQuery {
func entities(for identifiers: [DeckEntity.ID]) async throws -> [DeckEntity] {
try await DeckEntity.getAllDecks().filter { identifiers.contains($0.id) }
}
func suggestedEntities() async throws -> [DeckEntity] {
try await DeckEntity.getAllDecks()
}
func defaultResult() async -> DeckEntity? {
try? await suggestedEntities().first
}
}
I’ve tried reinstalling the app but it didn’t help. Since I followed “Making a configurable widget” tutorial from Apple documentation, I don’t know what is wrong but I guess the problem is somewhere in WidgetConfigurationIntent, AppEntity or EntityQuery.
Tomer Beilinson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.