Я пытаюсь создать намерение приложения, которое позволяет пользователю выбирать день в маршруте поездки. Поездка должна быть выбрана до того, как можно отобразить доступные дни. // Entity Definition:
import AppIntents
struct ShortcutsItineraryDayEntityDemo: Identifiable, Hashable, AppEntity {
typealias DefaultQuery = TripItineraryDayQueryDemo
static var typeDisplayRepresentation: TypeDisplayRepresentation = "Trip Itinerary Day"
var displayRepresentation: DisplayRepresentation {
"Trip Day"
}
var id: String
//static var defaultQuery: DefaultQuery = TripItineraryDayQuery()
static var defaultQuery: DefaultQuery {
TripItineraryDayQueryDemo()
}
init() {
self.id = UUID().uuidString //itineraryDay.id?.uuidString ?? itineraryDay.date.formatted()
}
}
struct TripItineraryDayQueryDemo: EntityQuery {
// This is only works in shortcut editor but not at runtime. Why? How can I fix this issue?
@IntentParameterDependency(\.$tripEntity)
var tripEntity
@IntentParameterDependency(\.$title)
var intentTitle
func entities(for identifiers: [ShortcutsItineraryDayEntityDemo.ID]) async throws -> [ShortcutsItineraryDayEntityDemo] {
print("entities being called with identifiers: \(identifiers)")
// This method is called when the app needs to fetch entities based on identifiers.
let tripsStore = TripsStore()
guard let trip = tripEntity?.tripEntity.trip,
let itineraryId = trip.firstItineraryId else {
print("No trip or itinerary ID can be found for the selected trip.")
return []
}
// Load the itinerary days for the trip
// filter and return the itinerary days that match the identifiers
return [] // return empty for this demo
}
func suggestedEntities() async throws -> [ShortcutsItineraryDayEntityDemo] {
print("suggested itinerary days being called")
let tripsStore = TripsStore()
guard let trip = tripEntity?.tripEntity.trip,
let itineraryId = trip.firstItineraryId else {
print("No trip or itinerary ID found for the selected trip.")
return []
}
return []
}
}
< /code>
import AppIntents
struct PlanActivityIntentDemo: AppIntent {
static var title: LocalizedStringResource { "Plan New Activity" }
// The selected trip fails to get injected when intent is run from shortcut app
@Parameter(title: "Trip", description: "The trip to plan an activity for", requestValueDialog: "Which trip would you like to plan an activity for?")
var tripEntity: ShortcutsTripEntity
@Parameter(title: "Activity Title", description: "The title of the activity", requestValueDialog: "What do you want to do or see?")
var title: String
@Parameter(title: "Activity Day", description: "Activity Day")
var activityDay: ShortcutsItineraryDayEntity
func perform() async throws -> some ProvidesDialog {
// This is a demo intent, so we won't actually perform any actions.
.result(dialog: "Activity '\(title)' planned")
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... app-intent
Как вводить зависимость параметров во время выполнения в приложении для iOS ⇐ IOS
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как вводить зависимость параметров во время выполнения в приложении для iOS
Anonymous » » в форуме IOS - 0 Ответы
- 6 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как вводить зависимость параметров во время выполнения в приложении для iOS
Anonymous » » в форуме IOS - 0 Ответы
- 8 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как вводить зависимость параметров во время выполнения в приложении для iOS
Anonymous » » в форуме IOS - 0 Ответы
- 3 Просмотры
-
Последнее сообщение Anonymous
-