Implement App Shortcuts with App Intents

RSS for tag

Discuss the WWDC22 Session Implement App Shortcuts with App Intents

Posts under wwdc2022-10170 tag

7 Posts
Sort by:
Post not yet marked as solved
5 Replies
2.1k Views
I am trying to create a shortcut following "Implement App Shortcuts With App Intents" talk from WWDC2022. The below is my MWE. In a standalone app, this can be extended and behave like the video. Adding this code to my main app, makes the shortcut show up within the Shortcuts app, but if I click on it, it pops up an alert saying Error Domain=LNActionForAutoShortcutPhraseFetchError Code=1 "Couldn't find AppShortcutsProvider" UserInfo={NSLocalizedDescription=Couldn't find AppShortcutsProvider} My main app has several targets, so I suppose I need to establish which one is the shortcuts provider, but I cannot find any reference to how to do this in the documents. Via Siri, the shortcut command is not recognised at all. import AppIntents import SwiftUI struct DoSomething: AppIntent {  static var title: LocalizedStringResource = "Do something"  func perform() async throws -> some IntentResult {   return .result()  }  static var openAppWhenRun: Bool = false } struct MyShortcuts: AppShortcutsProvider {  @AppShortcutsBuilder  static var appShortcuts: [AppShortcut] {   AppShortcut(    intent: DoSomething(),    phrases: ["Do Something in \(.applicationName)"],    systemImageName: "books.vertical.fill"   )  } }
Posted
by esroberts.
Last updated
.
Post not yet marked as solved
2 Replies
1.4k Views
I'm on Xcode 14.2 and running iOS 16.2 on my device (No betas). The intent does not appear in the shortcuts App. Here's my code.. import AppIntents @available(iOS 16.0, *) struct ShowRecentOrder: AppIntent {   static var title: LocalizedStringResource = "Show my orders"   static var description = IntentDescription("Shows list of orders")   @MainActor   func perform() async throws -> some IntentResult & ProvidesDialog {     let total = await getRecentOrder()     let dialog = IntentDialog(total)     return .result(dialog: dialog)   }   private func getRecentOrder() async -> LocalizedStringResource {     let result = await OrderServiceMock.fetchRecentOrder()     return LocalizedStringResource(stringLiteral: String(format: "%2.f", result))   } } @available(iOS 16.0, *) struct ShortcutsService: AppShortcutsProvider {   // Maximum of 10 App Shortcuts supported by Apple   @AppShortcutsBuilder static var appShortcuts: [AppShortcut] {     AppShortcut(       intent: ShowRecentOrder(),       phrases: [         "Show my recent order in \(.applicationName)",         "View my recent order in \(.applicationName)"       ]     )   }   static var shortcutTileColor: ShortcutTileColor { .tangerine } } class OrderServiceMock {   static func fetchRecentOrder() async -> String {     let mockOrders = ["Order 1", "order 2", "Order 3"]     return mockOrders.randomElement() ?? ""   } }
Posted
by Subhanc.
Last updated
.
Post not yet marked as solved
1 Replies
1.2k Views
We are developing an app for iOS 16 using App Intents and Siri. We have been testing the behavior of opening another App Intent by passing the opensIntent argument to the result function in the App Intent with iOS 16.4 devices. As a result, we found that the dialog text specified in the result argument of the Intent to which it transitions is not displayed and therefore does not work. And also found that when invoked from Siri, the Intent passed to the opensIntent argument is invoked "twice". Are these behaviors bugs? Any ideas? The following is a sample code and logs. import AppIntents struct PrimaryIntent: AppIntent { static var title: LocalizedStringResource = "Primary" func perform() async throws -> some OpensIntent { print("\(String(describing: Self.self)).\(#function): invoked") return .result(opensIntent: SecondaryIntent()) } } struct SecondaryIntent: AppIntent { static var title: LocalizedStringResource = "Secondary" func perform() async throws -> some ProvidesDialog { print("\(String(describing: Self.self)).\(#function): invoked") return .result(dialog: .init(stringLiteral: "test")) } } struct ShortcutsProvider: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut(intent: PrimaryIntent(), phrases: ["\(.applicationName)"]) } } logs from Shortcut App PrimaryIntent.perform(): invoked SecondaryIntent.perform(): invoked # is not displayed dialog... logs from Siri PrimaryIntent.perform(): invoked SecondaryIntent.perform(): invoked SecondaryIntent.perform(): invoked # is not displayed dialog... # SecondaryIntent invoked twice...
Posted
by wtrnmk12.
Last updated
.
Post not yet marked as solved
1 Replies
1.5k Views
Hello, I am working on an app that uses App Intents to enable users to interact with Siri. Here is the code I'm using: struct SiriPassMeLuna: AppIntent { static var title: LocalizedStringResource = "Pass me Luna" static var description = IntentDescription("Lets you query Luna and receive a response.") @Parameter(title: "Phrase") var phrase: String? func perform() async throws -> some IntentResult { guard let providedPhrase = phrase else { throw $phrase.needsValueError("What do you need help with?") } let request = Request() let reply = request.sendRequest(transcription: providedPhrase) return .result(dialog: "\(reply)") } } struct SiriAppShortcuts: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut( intent: SiriPassMeLuna(), phrases: ["Pass me \(.applicationName)"] ) } } My goal is to create a continuous conversation with Siri, where the user can speak to the intent, and then the intent keeps listening and replying without the user having to invoke Siri and the intent each time. Is there a way to achieve this behavior, so that the conversation with Siri is more seamless, and the user doesn't have to repeatedly say "Hey Siri" followed by the intent name? Any guidance or suggestions would be greatly appreciated. Thank you!
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.4k Views
I'm using the AppIntents framework introduced in iOS 16. My goal is to create an AppIntent that performs a long-running task but does open my app when run. When I run the Intent from the Shortcuts app, I see an error message that says the shortcut "was interrupted because it didn't finish executing in time." Is there a way to signal progress to the user of a long-running AppIntent or get more time from the system prior to the AppIntent being cancelled?
Posted Last updated
.
Post not yet marked as solved
2 Replies
878 Views
Here is my code : struct NoteIntent: AppIntent { // 3 static var title: LocalizedStringResource = "Write memo" static var openAppWhenRun: Bool = false // 4 @Parameter(title: "Input") var input: String? // 5 @MainActor func perform() async throws -> some ProvidesDialog & IntentResult { guard let providedPhrase = input else { InputViewModel.shared.firstSiriNote = nil throw $input.needsValueError( "Write something") } return .result(dialog: IntentDialog("👏🏻Success!")) } static var parameterSummary: some ParameterSummary { Summary("\(\.$input)") } } My problem is that in Shortcut app input sting parameter only call default keboard,i can't switch third part keyboard or other launguge type
Posted
by lord30590.
Last updated
.