$30 off During Our Annual Pro Sale. View Details »

アクションボタンから始める App Intents の再入門

アクションボタンから始める App Intents の再入門

YUMEMI.grow Mobile #7 - connpass
https://yumemi.connpass.com/event/296373/

サンプルアプリ
https://github.com/mitsuharu/AppIntentsSample

Mitsuharu Emoto

October 11, 2023
Tweet

More Decks by Mitsuharu Emoto

Other Decks in Programming

Transcript

  1. ࣮૷͢Δίʔυ͸جຊతʹ͜Ε͚ͩ import AppIntents struct OpenApp: AppIntent { static let title:

    LocalizedStringResource = "[σϞΞϓϦ]ΞϓϦΛ։͘" // ࣮ߦ࣌ʹΞϓϦΛىಈ͍ͨ͠৔߹͸true static var openAppWhenRun: Bool = true // ࣮ߦ͢Δॲཧ͓ΑͼγϣʔτΧοτͷ໭Γ஋Λઃఆ͢Δ @MainActor func perform() async throws -> some IntentResult { // ΞϓϦͰ࣮ߦ͍ͨ͠ॲཧΛॻ͘ʢasyncؔ਺ͳͷͰAPIϦΫΤετ΋Մೳʣ return .result() } // γϣʔτΧοτΞϓϦͰͷදࣔʢ͜Ε͸লུՄʣ static var parameterSummary: some ParameterSummary { Summary("Open App") } } 7
  2. બ୒ࣜͷೖྗ struct OpenBakufu: AppIntent { static let title: LocalizedStringResource =

    "[σϞΞϓϦ]ນ෎Λ։͘" static var openAppWhenRun: Bool = true // title ͸γϣʔτΧοτΞϓϦͰϓϨʔεϗϧμʔ @Parameter(title: "ນ෎໊") var bakufu: BakufuType @MainActor func perform() async throws -> some IntentResult { // γϯάϧτϯͳViewModelͰೖྗΛΞϓϦຊମ΁౉͢ ViewModel.shared.update(bakufuType: bakufu) return .result() } static var parameterSummary: some ParameterSummary { Summary("Open \(\.$bakufu)") } } enum BakufuType: String { case kamakura = "ח૔ນ෎" case muromachi = "ࣨொນ෎" case edo = "ߐށນ෎" } extension BakufuType: AppEnum { // ΧελϜλΠϓͷදࣔ static var typeDisplayRepresentation: TypeDisplayRepresentation = "ນ෎" // ਓ͕ಡΉͨΊͷࣙॻϦςϥϧ static var caseDisplayRepresentations: [BakufuType: DisplayRepresentation] = [ .kamakura: "ח૔ນ෎", .muromachi: "ࣨொນ෎", .edo: "ߐށນ෎", ] } 10
  3. ΞϓϦ͔ΒγϣʔτΧοτΛఏڙ͢Δ w ࡞੒ͨ͠*OUFOUΛγϣʔτΧοτͱͯ͠ఏڙ͢Δ w ͜ͷγϣʔτΧοτ͸4JSJ΍4QPUMJHIUͰఏҊ͞ΕΔ import AppIntents struct IntentProvider: AppShortcutsProvider

    { static var appShortcuts: [AppShortcut] { return [ // phrases ͸ Siri ͕ೝࣝʹར༻͢ΔʢͦͷͨΊΞϓϦ໊͸ඞਢʣ AppShortcut(intent: OpenApp(), phrases: ["\(.applicationName)ͰΞϓϦΛ։ͯ"]), AppShortcut(intent: OpenBakufu(), phrases: ["\(.applicationName)Ͱນ෎Λ։ͯ"]) ] } } 12
  4. ࢀߟ w "QQ*OUFOUTc"QQMF%FWFMPQFS%PDVNFOUBUJPO w IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOBQQJOUFOUT w %JWFJOUP"QQ*OUFOUT 88%$  w

    IUUQTEFWFMPQFSBQQMFDPNWJEFPTQMBZXXED w ʲJ04ʳ"QQ*OUFOUTͰ"QQγϣʔτΧοτΛ࡞੒͢Δ w IUUQT[FOOEFWOBPZB@NBFEBBSUJDMFTGFC 16