App Intent 란? Shortcut, Spotlight, Widgets, Action Button을 포함한 많은 기능, 새로운 애플펜슬 스퀴즈 를 통해 앱 Entity를 표출할 수 있도록 도와주는 기능입니다. 이번에 App Intent 는 Apple Intelligence 와 Controls 에도 적용됩니다
struct OpenPinnedTrail: AppIntent {
static let title: LocalizedStringResource = "Open Pinned Trail"
func perform() async throws -> some IntentResult {
NavigationModel.shared.navigate(to: .pinned)
return .result()
}
static let openAppWhenRun: Bool = true
}
struct OpenTrail: AppIntent, OpenIntent { // OpenIntent는 openAppWhenRun 기능
static let title: LocalizedStringResource = "Open Pinned Trail"
@Parameter(title: "Trail")
var target: TrailEntity // 아래 코드참고
func perform() async throws -> some IntentResult {
NavigationModel.shared.navigate(to: .target)
return .result()
}
static var parameterSummary: some ParameterSummary {
Summary("Open \(\.$trail)")
}
}
struct TrailEntity: AppEntity {
@Property(title: "Trail Name")
var name: String
static let typeDisplayRepresentation: TypeDisplayRepresentation = "Trail"
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: name), image: Image(named: imageName)
}
var id: Trail.ID
static var defaultQuery = TrailEntityQuery()
}
struct TrailEntityQuery: EntityQeury {
func entities(for identifiers: [TrailEntity.ID]) async throws -> [TrailEntity] {
TrailDataManager.shared.trails(with: identifiers)
.map { TrailEntity(trail: $0) }
}
}
extension TrailEntityQuery: EnumerableEntityQuery {
func allEntities() async throws -> [TrailEntity] {
TrailDataManager.shared.trails
.map { TrailEntity(trail: $0) }
}
}
parameterSummary 적용
이전 | 이후 |
---|---|
![]() |
![]() |
Trail 탭 시, 앱 동작확인 [Bring your app’s core features to users with App Intents][15:26]
struct TrailShortcuts: AppShorcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: OpenPinnedTrail(),
phrases: [
"Open my pinned trail in \(.applicationName)",
"Show my pinned trail in \(.applicationName)",
],
shortTitle: "Open Pinned Trail",
systemImageName: "pin"
)
}
}
Widget을 더욱 커스텀하고 싶다면 [Explore enhancements to App Intents WWDC23]를 확인해주세요.
Control Center에서의 App Intent 활용에 대해 알고싶다면 [Extend your app's controls across the system WWDC24] 를 확인해주세요.