Bring your app's core features to users with App Intents (WWDC24)

Wongbing·2024년 7월 8일
0

WWDC

목록 보기
7/7

App Intent 란? Shortcut, Spotlight, Widgets, Action Button을 포함한 많은 기능, 새로운 애플펜슬 스퀴즈 를 통해 앱 Entity를 표출할 수 있도록 도와주는 기능입니다. 이번에 App Intent 는 Apple Intelligence 와 Controls 에도 적용됩니다

⚙️ 어떤 기능인가?

  • Siri 를 통해 Spotlight를 거쳐 특정 앱의 특정 페이지로 이동하는 것이 가능합니다 .
  • 특정 앱의 특정 페이지로 이동하기 액션을 Widget 으로 만드는 것이 가능합니다.
  • Control Center에 이 위젯을 추가하는 것도 가능합니다 .
  • 이 기능으로 당신의 앱에 대한 경험을 개인화시켜줄 수 있습니다 .

⚙️ 개념

  • 크게 세가지 카테고리가 있습니다. Intents, Entities, App shortcuts
    • Intents : 뷰를 열거나, hike를 시작하는 액션을 수행합니다. (동사)
    • Entities : 객체입니다 .(명사)
    • App shortcuts : 동사와 명사를 합친 문장입니다.

1. Intent

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)")
    }
}
  • 위와같이 생성해주면 Shortcut 앱에서 나의 앱에 대한 새로운 Intent 로 "OpenPinnedTrail" 이 생기게 되고 액션을 실행해줄 수 있습니다.
  • 위 액션을 실행하는 하나의 단축어를 만들어 홈스크린에 앱아이콘으로 만들어줄 수 있습니다. 앱을 클릭하면 입력된 액션이 수행됩니다.

2. Entities

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]

3. App Shortcuts

  • 앱이 실행되지 않아도 되는 기능에 대해 App Shortcut 을 만들어서 Siri 또는 Spotlight에서 접근 가능하도록 만들 수 있습니다.
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] 를 확인해주세요.

profile
IOS 앱개발 공부

0개의 댓글