Implement App Shortcuts with App Intents

RSS for tag

Discuss the WWDC22 Session Implement App Shortcuts with App Intents

Posts under wwdc2022-10170 tag

34 Posts

Post

Replies

Boosts

Views

Activity

Using Maps in App Intents
I want to use MapKit with App Intents, but the map does not show up.(See attached image) Can anyone help me solve this? import SwiftUI import MapKit struct ContentView: View {   @State private var region = MKCoordinateRegion(     center: CLLocationCoordinate2D(latitude: 37.334_900,                     longitude: -122.009_020),     latitudinalMeters: 750,     longitudinalMeters: 750   )       var body: some View {     VStack {       Map(coordinateRegion: $region).frame(width:300, height:300)         .disabled(true)     }   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } } import AppIntents import SwiftUI import MapKit struct test20220727bAppIntentsExtension: AppIntent {   static var title: LocalizedStringResource = "test20220727bAppIntentsExtension"       func perform() async throws -> some IntentResult {     return .result(value: "aaa", view: ContentView())   } } struct testShortcuts:AppShortcutsProvider{   @available(iOS 16.0, *)   static var appShortcuts: [AppShortcut]{     AppShortcut(       intent: test20220727bAppIntentsExtension(),       phrases: ["test20220727bAppIntentsExtension" ]     )   } }
2
0
1.3k
Mar ’25
AppIntent with long-running perform()
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?
3
1
2.3k
Jan ’25
App Shortcut "Couldn't find AppShortcutsProvider"
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"   )  } }
5
1
3.3k
Sep ’23
App Intent Not Appearing in Shortcuts App
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() ?? ""   } }
3
1
1.7k
Aug ’23
App Intents with OpensIntent does not work correctly
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...
3
1
2.2k
Aug ’23
Creating a Continuous Conversation with Siri Using App Intents
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!
1
0
2.2k
Jun ’23
App Intents string type parameter in Shortcut app can't change keyboard
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
3
0
1.5k
May ’23
App Intents don't show on device, while they do in the simulator
Hello. I want to provide my users with some useful shortcuts and chose AppIntents to do so. I watched the relevant WWDC talks, read the documentation and I set up a few simple intents, adhering to AppIntent. I also created a AppShortcutsProvider to offer the most useful of my intents on installation. I did use \(.applicationName) within my phrases. Trying it out on the simulator, it works as intended (Ventura 13.3, Xcode 14.3, iOS 16.4). Wonderful! Now, building the same code for my hardware device (iPhone SE 3rd Gen, iOS 16.4) and trying it out on there, nothing shows up - neither the intents I want to add on install, nor the ones the user would have to select manually. I really have no idea why... On a side note: My app does have a Watch counterpart and I'd like to do the same there, but with intents specific to the Watch app. They don't even show up in the simulator, though. Any ideas what could've went wrong here? I'd appreciate it. Thanks!
3
0
3.3k
Apr ’23
AppShortcutsProvider pharses not recognizable by Siri
We have implemented AppIntents in iOS16 and the shortcuts are working fine when manually added in shortcuts app. But the shortcuts created programaticaly using AppShortcutsProvider with AppShortcutsPhrases are not at all recognized by Siri. The AppIntents core feature is zero setup shortcuts, but it is not working as expected. Please suggest any fix for this. Sample Code: struct NotesShortcutProvider: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { let shortcut = AppShortcut(intent: ShowTodayTasks(), phrases: ["Show today tasks","show my tasks today"]) return [shortcut] } } Tried with applicationName as well but no luck.
4
2
2.8k
Apr ’23
Not seeing a Default View running my intent.
The talk describes a Default View displayed whenever running my intent (7:32). I never see any view other than the Siri interaction at the bottom. Are there other requirements for getting the Default View to display? I have experimented with adding a custom snippet view to the result: func perform() async throws -> some IntentResult & ProvidesDialog & ShowsSnippetView { ... return .result( dialog: "\(response)", view: IntentSnippetView(prompt) ) That does display, but has way too much information. My IntentSnippetView only has a single Text("Hello World") but the view shows the entire contents of the response value as well. Is there any way to limit what actually shows up in the response snippet view? Is there any way to get the described Default View to show while the intent is running? The talk also suggests custom views can be shown at Intent Confirmation and Value Confirmation. In my case neither of those seem applicable since those confirmation steps are not used. I'd really like to have at least the Default View, or be able to make the result view less overwhelming. I've looked through the documentation, but don't find much about custom widget views or intent views - any pointers would be appreciated! Here's my code just in case its clear I'm doing something wrong: import AppIntents struct AskMyApp: AppIntent {     static var title: LocalizedStringResource = "Ask"     static var description: IntentDescription = IntentDescription("This will ask MyApp")     static var openAppWhenRun = false     @Parameter(title: "Prompt", description: "The prompt to send", requestValueDialog: IntentDialog("What would you like to ask?"))     var prompt: String     @MainActor     func perform() async throws -> some IntentResult & ProvidesDialog & ShowsSnippetView {         let response = ViewModel.shared.sendIntentPrompt(newPrompt: prompt)         return .result(             dialog: "\(response)",             view: AskMyAppSnippetView(prompt)         )     }     static var parameterSummary: some ParameterSummary {         Summary("Ask \(\.$prompt)")     } } import SwiftUI struct AskMyAppSnippetView: View {     var body: some View {         Text("Hello World")     } }
2
0
1.4k
Mar ’23
Assign a category name to the Find intent generated by EntityPropertyQuery
In an AppIntent we can declare an IntentDescription with a categoryName to group similar intents: struct OpenArtist: AppIntent { static var description: IntentDescription = IntentDescription("Opens a specific artist.", categoryName: "artistsSection") // Additional properties } But how can we assign the same category to the "Find AppEntity" intent generated when we declare an EntityPropertyQuery? I want to group it along with the other intents that handle the same entity, but since it is generated by the system, I don't know how to assign a category to it.
2
2
1.5k
Mar ’23
Siri not audibly saying results from requestDisambiguation
I have an Intent that creates a list of items for the user to select from and use the .requestDisambiguation() call return to the user. The list is displayed in the shortcuts app but when using Siri only the dialog is said to the user. I need the among values to also be read out loud. Any suggestions. let item = try await $itemInfo.requestDisambiguation(         among: infoList, dialog: IntentDialog("Which item?") )
0
0
1k
Feb ’23
Difference between Custom Intents and App Intents
Hi everyone. Can someone explain the difference between custom intents and app intents, and provide documentation for the type of intent needed to create a shortcut from an installed app with the same functionality as the manual "repeat text" shortcut created on my phone which listens for speech and repeats it using Siri speakers?
0
0
1k
Feb ’23
AppIntent Date parameter returns wrong value
I'm implementing an AppIntent of my macOS app (not iOS). It has a non-optional Date parameter like so: @Parameter(   title: LocalizedStringResource("AppIntent.parameter.date"), requestValueDialog: IntentDialog(LocalizedStringResource("AppIntent.parameter.date.requestValue"))   ) var date: Date ... static var parameterSummary: some ParameterSummary { Summary("Remind me about \(\.$title) at \(\.$date)") } In the Shortcuts app it shows up fine and everything works if I actually enter a date in the summary. If the parameter is empty when running the intent, the "requestValue" dialog pops up asking for a date with a date picker. However, the returned date is always 7 hours in the future. E.g. I enter a date with 11:00am, then it would return the same date but with 6:00pm. Am I doing something wrong or is this a bug in Shortcuts?
0
0
1.8k
Jan ’23
LocalizedStringResource with Formatter
I am trying to use DateComponentsFormatter() with my AppIntent, but I can not find a way to localize the formatter string with the same language that LocalizedStringResource use... Example (My App: Arabic, Device: English, Siri: English) let formatter = DateComponentsFormatter()     formatter.unitsStyle = .full     formatter.maximumUnitCount = 2     formatter.allowedUnits = [.hour, .minute]     formatter.includesTimeRemainingPhrase = true let relativeDate = formatter.string(from: .now, to: nextEvent.date) ?? ""      return .result(             value: value,             dialog: "intent_current_event\(relativeDate)"           ) The result is: Next event متبقي 4 ساعات و 5 دقائق The relativeDate is in Arabic (App Language) and the "intent_current_event%@" localized in English (Siri Language) Can anyone please help me to use the Formatter and get it to localized the same local as LocalizedStringResource.
3
0
2.0k
Dec ’22
Looking for implementation code of apple login using js for web
Hi, I hope this email finds you in the best of your spirits. I am looking for implementation code for implementing apple login using js for the web. I followed what is available on the apple website https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js/configuring_your_webpage_for_sign_in_with_apple But I am getting an Invalid web redirect URL message error. (I have verified that the redirect url is correct and correctly setup) A complete implementation demo code showing the apple login implementation would be of huge help. Thanks in advance. Regards Debopriyo
0
0
792
Dec ’22
App Intents, put `@Parameter` into `ParameterSummary` or drop-down list
Hello, On the wwdc22 Dive into App Intents video in 16:08 you can see that part of parameters are in ParamaterSummary and one is in the drop-down menu. When I am adding a ParamaterSummary to my AppIntent the drop-down menu is disapearing so part of my parameters is not able to set. I have tried force to display drop-down menu by chosing specific result of perform() method by even that the parameters are not displayed there. How can I split parameters into ParamaterSummary or drop-down list? Best, Marcin
0
0
1.2k
Nov ’22
Testing out App Intents and running into some issues
I have scaled down one of the Apps I am working on to use to learn how to program App Intents and utilize Siri in my apps. I will post the scaled down version of my code below to its simplest form. This is a simple App that merely keeps a total in an @State var named counter. The App shows the current total along with 2 buttons, one button being labeled "minus" the other labeled "add". When someone taps the minus button, 1 is subtracted from the counter if the counter is greater than 0. When someone taps the plus button, 1 is added to the counter as long as it is not greater than 10,000. The buttons actually call functions called decrementCounter and incrementCounter which does the math and updates the value of the state variable counter. The App works just fine as is. Minus and plus buttons work and the view is updated to reflect the current value of counter as buttons are pushed. The problem is when I try to use an App Intent to add or subtract from the counter. In this example, I only put in two App Intents, one to add to the counter and the other to have siri tell you what the current value of the counter is. The app intent called SiriAddOne calls the same function as is used when a button is pressed, however, the counter does not get incremented. Also the app intent SiriHowMany will always tell you the counter is zero. It's like the App Intents are not able to access the counter variable used in the view. I do know that the functions are being called because in my main program where I extracted this from, the incrementCounter and decrementCounter functions do others things as well. Those other things all work when I use the App Intent to call the function, but the counter variable remains unchanged. Hopefully someone can tell me what I am doing wrong here or how I need to go about doing this correctly. Thank you.. Here is the code: import SwiftUI import AppIntents struct ContentView: View { // This variable counter is the only thing that changes // and should be what forces the view to update @State var counter = 0         var body: some View {         VStack {             Spacer()             Text("Total")             // Displays the current value of the counter             Text(String(counter))             Spacer()             // When button is pressed call decrementCounter function             Button(action: {                 decrementCounter()             }, label: {                 Text("Minus")             })             Spacer()             // When button is pressed call incrementCounter function             Button(action: {                 incrementCounter()             }, label: {                 Text("Add")             })             Spacer()         }         .padding()     }          // subtract 1 from the counter     // when this happens the view should update to     // to reflect the new value.     func decrementCounter() {         if counter > 0 {             counter -= 1         }         return     }     // Add 1 to the counter     // when this happens the view should update to     // to reflect the new value.     func incrementCounter() {         if counter <= 9999 {             counter += 1         }         return     }        // Set up App Intent, perform action when matched     // and have siri state it has been done.     @available(iOS 16, *)     struct SiriAddOne: AppIntent {         static var title: LocalizedStringResource = "Add 1"         static var description = IntentDescription("Adds 1 to the counter")         @MainActor         func perform() async throws -> some IntentResult {             ContentView().incrementCounter()             return .result(dialog: "Okay, added 1 to counter.")             }         }     // Set up App Intent, perform action when matched     // and have siri state the current value of the counter.     @available(iOS 16, *)     struct SiriHowMany: AppIntent {         static var title: LocalizedStringResource = "How Many"         static var description = IntentDescription("How Many?")         func perform() async throws -> some IntentResult {             return .result(dialog: "You have  \(ContentView().counter).")             }         }     // Defines the two shortcut phrases to be used to call the two AppIntents     @available(iOS 16, *)     struct SiriAppShortcuts: AppShortcutsProvider {         static var appShortcuts: [AppShortcut] {             AppShortcut(                 intent: SiriAddOne(),                 phrases: ["Add one to \(.applicationName)"]             )             AppShortcut(                 intent: SiriHowMany(),                 phrases: ["How many \(.applicationName)"]             )         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
1
0
1.9k
Oct ’22
App Intents does not work with standalone watchOS
I am trying to create an appIntent for a standalone watchOS App but it never shows up in the shortcuts app on the watch. Works fine for an iPhone app. What am I missing here ? import AppIntents struct intenttest: AppIntent {     static var title: LocalizedStringResource = "intent "     func perform() async throws -> some IntentResult {         return .result()     } } struct LibraryAppShorcuts: AppShortcutsProvider {     @AppShortcutsBuilder static var appShortcuts: [AppShortcut] {         AppShortcut(intent: intenttest(),                     phrases: ["My something phrase in \(.applicationName)"])     } }
1
1
971
Oct ’22
Using Maps in App Intents
I want to use MapKit with App Intents, but the map does not show up.(See attached image) Can anyone help me solve this? import SwiftUI import MapKit struct ContentView: View {   @State private var region = MKCoordinateRegion(     center: CLLocationCoordinate2D(latitude: 37.334_900,                     longitude: -122.009_020),     latitudinalMeters: 750,     longitudinalMeters: 750   )       var body: some View {     VStack {       Map(coordinateRegion: $region).frame(width:300, height:300)         .disabled(true)     }   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } } import AppIntents import SwiftUI import MapKit struct test20220727bAppIntentsExtension: AppIntent {   static var title: LocalizedStringResource = "test20220727bAppIntentsExtension"       func perform() async throws -> some IntentResult {     return .result(value: "aaa", view: ContentView())   } } struct testShortcuts:AppShortcutsProvider{   @available(iOS 16.0, *)   static var appShortcuts: [AppShortcut]{     AppShortcut(       intent: test20220727bAppIntentsExtension(),       phrases: ["test20220727bAppIntentsExtension" ]     )   } }
Replies
2
Boosts
0
Views
1.3k
Activity
Mar ’25
AppIntent with long-running perform()
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?
Replies
3
Boosts
1
Views
2.3k
Activity
Jan ’25
App Shortcut "Couldn't find AppShortcutsProvider"
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"   )  } }
Replies
5
Boosts
1
Views
3.3k
Activity
Sep ’23
Set openAppWhenRun variable in AppIntent programatically.
I need to set the openAppWhenRun:Bool dynamically in App Intent. Eventhough I set this way. the app does not open when run the shortcut automation. static var openAppWhenRun:Bool { myNumber == 4 ? true : false }
Replies
5
Boosts
1
Views
4.2k
Activity
Sep ’23
App Intent Not Appearing in Shortcuts App
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() ?? ""   } }
Replies
3
Boosts
1
Views
1.7k
Activity
Aug ’23
App Intents with OpensIntent does not work correctly
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...
Replies
3
Boosts
1
Views
2.2k
Activity
Aug ’23
Creating a Continuous Conversation with Siri Using App Intents
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!
Replies
1
Boosts
0
Views
2.2k
Activity
Jun ’23
App Intents string type parameter in Shortcut app can't change keyboard
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
Replies
3
Boosts
0
Views
1.5k
Activity
May ’23
App Intents don't show on device, while they do in the simulator
Hello. I want to provide my users with some useful shortcuts and chose AppIntents to do so. I watched the relevant WWDC talks, read the documentation and I set up a few simple intents, adhering to AppIntent. I also created a AppShortcutsProvider to offer the most useful of my intents on installation. I did use \(.applicationName) within my phrases. Trying it out on the simulator, it works as intended (Ventura 13.3, Xcode 14.3, iOS 16.4). Wonderful! Now, building the same code for my hardware device (iPhone SE 3rd Gen, iOS 16.4) and trying it out on there, nothing shows up - neither the intents I want to add on install, nor the ones the user would have to select manually. I really have no idea why... On a side note: My app does have a Watch counterpart and I'd like to do the same there, but with intents specific to the Watch app. They don't even show up in the simulator, though. Any ideas what could've went wrong here? I'd appreciate it. Thanks!
Replies
3
Boosts
0
Views
3.3k
Activity
Apr ’23
AppShortcutsProvider pharses not recognizable by Siri
We have implemented AppIntents in iOS16 and the shortcuts are working fine when manually added in shortcuts app. But the shortcuts created programaticaly using AppShortcutsProvider with AppShortcutsPhrases are not at all recognized by Siri. The AppIntents core feature is zero setup shortcuts, but it is not working as expected. Please suggest any fix for this. Sample Code: struct NotesShortcutProvider: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { let shortcut = AppShortcut(intent: ShowTodayTasks(), phrases: ["Show today tasks","show my tasks today"]) return [shortcut] } } Tried with applicationName as well but no luck.
Replies
4
Boosts
2
Views
2.8k
Activity
Apr ’23
Not seeing a Default View running my intent.
The talk describes a Default View displayed whenever running my intent (7:32). I never see any view other than the Siri interaction at the bottom. Are there other requirements for getting the Default View to display? I have experimented with adding a custom snippet view to the result: func perform() async throws -> some IntentResult & ProvidesDialog & ShowsSnippetView { ... return .result( dialog: "\(response)", view: IntentSnippetView(prompt) ) That does display, but has way too much information. My IntentSnippetView only has a single Text("Hello World") but the view shows the entire contents of the response value as well. Is there any way to limit what actually shows up in the response snippet view? Is there any way to get the described Default View to show while the intent is running? The talk also suggests custom views can be shown at Intent Confirmation and Value Confirmation. In my case neither of those seem applicable since those confirmation steps are not used. I'd really like to have at least the Default View, or be able to make the result view less overwhelming. I've looked through the documentation, but don't find much about custom widget views or intent views - any pointers would be appreciated! Here's my code just in case its clear I'm doing something wrong: import AppIntents struct AskMyApp: AppIntent {     static var title: LocalizedStringResource = "Ask"     static var description: IntentDescription = IntentDescription("This will ask MyApp")     static var openAppWhenRun = false     @Parameter(title: "Prompt", description: "The prompt to send", requestValueDialog: IntentDialog("What would you like to ask?"))     var prompt: String     @MainActor     func perform() async throws -> some IntentResult & ProvidesDialog & ShowsSnippetView {         let response = ViewModel.shared.sendIntentPrompt(newPrompt: prompt)         return .result(             dialog: "\(response)",             view: AskMyAppSnippetView(prompt)         )     }     static var parameterSummary: some ParameterSummary {         Summary("Ask \(\.$prompt)")     } } import SwiftUI struct AskMyAppSnippetView: View {     var body: some View {         Text("Hello World")     } }
Replies
2
Boosts
0
Views
1.4k
Activity
Mar ’23
Assign a category name to the Find intent generated by EntityPropertyQuery
In an AppIntent we can declare an IntentDescription with a categoryName to group similar intents: struct OpenArtist: AppIntent { static var description: IntentDescription = IntentDescription("Opens a specific artist.", categoryName: "artistsSection") // Additional properties } But how can we assign the same category to the "Find AppEntity" intent generated when we declare an EntityPropertyQuery? I want to group it along with the other intents that handle the same entity, but since it is generated by the system, I don't know how to assign a category to it.
Replies
2
Boosts
2
Views
1.5k
Activity
Mar ’23
Siri not audibly saying results from requestDisambiguation
I have an Intent that creates a list of items for the user to select from and use the .requestDisambiguation() call return to the user. The list is displayed in the shortcuts app but when using Siri only the dialog is said to the user. I need the among values to also be read out loud. Any suggestions. let item = try await $itemInfo.requestDisambiguation(         among: infoList, dialog: IntentDialog("Which item?") )
Replies
0
Boosts
0
Views
1k
Activity
Feb ’23
Difference between Custom Intents and App Intents
Hi everyone. Can someone explain the difference between custom intents and app intents, and provide documentation for the type of intent needed to create a shortcut from an installed app with the same functionality as the manual "repeat text" shortcut created on my phone which listens for speech and repeats it using Siri speakers?
Replies
0
Boosts
0
Views
1k
Activity
Feb ’23
AppIntent Date parameter returns wrong value
I'm implementing an AppIntent of my macOS app (not iOS). It has a non-optional Date parameter like so: @Parameter(   title: LocalizedStringResource("AppIntent.parameter.date"), requestValueDialog: IntentDialog(LocalizedStringResource("AppIntent.parameter.date.requestValue"))   ) var date: Date ... static var parameterSummary: some ParameterSummary { Summary("Remind me about \(\.$title) at \(\.$date)") } In the Shortcuts app it shows up fine and everything works if I actually enter a date in the summary. If the parameter is empty when running the intent, the "requestValue" dialog pops up asking for a date with a date picker. However, the returned date is always 7 hours in the future. E.g. I enter a date with 11:00am, then it would return the same date but with 6:00pm. Am I doing something wrong or is this a bug in Shortcuts?
Replies
0
Boosts
0
Views
1.8k
Activity
Jan ’23
LocalizedStringResource with Formatter
I am trying to use DateComponentsFormatter() with my AppIntent, but I can not find a way to localize the formatter string with the same language that LocalizedStringResource use... Example (My App: Arabic, Device: English, Siri: English) let formatter = DateComponentsFormatter()     formatter.unitsStyle = .full     formatter.maximumUnitCount = 2     formatter.allowedUnits = [.hour, .minute]     formatter.includesTimeRemainingPhrase = true let relativeDate = formatter.string(from: .now, to: nextEvent.date) ?? ""      return .result(             value: value,             dialog: "intent_current_event\(relativeDate)"           ) The result is: Next event متبقي 4 ساعات و 5 دقائق The relativeDate is in Arabic (App Language) and the "intent_current_event%@" localized in English (Siri Language) Can anyone please help me to use the Formatter and get it to localized the same local as LocalizedStringResource.
Replies
3
Boosts
0
Views
2.0k
Activity
Dec ’22
Looking for implementation code of apple login using js for web
Hi, I hope this email finds you in the best of your spirits. I am looking for implementation code for implementing apple login using js for the web. I followed what is available on the apple website https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js/configuring_your_webpage_for_sign_in_with_apple But I am getting an Invalid web redirect URL message error. (I have verified that the redirect url is correct and correctly setup) A complete implementation demo code showing the apple login implementation would be of huge help. Thanks in advance. Regards Debopriyo
Replies
0
Boosts
0
Views
792
Activity
Dec ’22
App Intents, put `@Parameter` into `ParameterSummary` or drop-down list
Hello, On the wwdc22 Dive into App Intents video in 16:08 you can see that part of parameters are in ParamaterSummary and one is in the drop-down menu. When I am adding a ParamaterSummary to my AppIntent the drop-down menu is disapearing so part of my parameters is not able to set. I have tried force to display drop-down menu by chosing specific result of perform() method by even that the parameters are not displayed there. How can I split parameters into ParamaterSummary or drop-down list? Best, Marcin
Replies
0
Boosts
0
Views
1.2k
Activity
Nov ’22
Testing out App Intents and running into some issues
I have scaled down one of the Apps I am working on to use to learn how to program App Intents and utilize Siri in my apps. I will post the scaled down version of my code below to its simplest form. This is a simple App that merely keeps a total in an @State var named counter. The App shows the current total along with 2 buttons, one button being labeled "minus" the other labeled "add". When someone taps the minus button, 1 is subtracted from the counter if the counter is greater than 0. When someone taps the plus button, 1 is added to the counter as long as it is not greater than 10,000. The buttons actually call functions called decrementCounter and incrementCounter which does the math and updates the value of the state variable counter. The App works just fine as is. Minus and plus buttons work and the view is updated to reflect the current value of counter as buttons are pushed. The problem is when I try to use an App Intent to add or subtract from the counter. In this example, I only put in two App Intents, one to add to the counter and the other to have siri tell you what the current value of the counter is. The app intent called SiriAddOne calls the same function as is used when a button is pressed, however, the counter does not get incremented. Also the app intent SiriHowMany will always tell you the counter is zero. It's like the App Intents are not able to access the counter variable used in the view. I do know that the functions are being called because in my main program where I extracted this from, the incrementCounter and decrementCounter functions do others things as well. Those other things all work when I use the App Intent to call the function, but the counter variable remains unchanged. Hopefully someone can tell me what I am doing wrong here or how I need to go about doing this correctly. Thank you.. Here is the code: import SwiftUI import AppIntents struct ContentView: View { // This variable counter is the only thing that changes // and should be what forces the view to update @State var counter = 0         var body: some View {         VStack {             Spacer()             Text("Total")             // Displays the current value of the counter             Text(String(counter))             Spacer()             // When button is pressed call decrementCounter function             Button(action: {                 decrementCounter()             }, label: {                 Text("Minus")             })             Spacer()             // When button is pressed call incrementCounter function             Button(action: {                 incrementCounter()             }, label: {                 Text("Add")             })             Spacer()         }         .padding()     }          // subtract 1 from the counter     // when this happens the view should update to     // to reflect the new value.     func decrementCounter() {         if counter > 0 {             counter -= 1         }         return     }     // Add 1 to the counter     // when this happens the view should update to     // to reflect the new value.     func incrementCounter() {         if counter <= 9999 {             counter += 1         }         return     }        // Set up App Intent, perform action when matched     // and have siri state it has been done.     @available(iOS 16, *)     struct SiriAddOne: AppIntent {         static var title: LocalizedStringResource = "Add 1"         static var description = IntentDescription("Adds 1 to the counter")         @MainActor         func perform() async throws -> some IntentResult {             ContentView().incrementCounter()             return .result(dialog: "Okay, added 1 to counter.")             }         }     // Set up App Intent, perform action when matched     // and have siri state the current value of the counter.     @available(iOS 16, *)     struct SiriHowMany: AppIntent {         static var title: LocalizedStringResource = "How Many"         static var description = IntentDescription("How Many?")         func perform() async throws -> some IntentResult {             return .result(dialog: "You have  \(ContentView().counter).")             }         }     // Defines the two shortcut phrases to be used to call the two AppIntents     @available(iOS 16, *)     struct SiriAppShortcuts: AppShortcutsProvider {         static var appShortcuts: [AppShortcut] {             AppShortcut(                 intent: SiriAddOne(),                 phrases: ["Add one to \(.applicationName)"]             )             AppShortcut(                 intent: SiriHowMany(),                 phrases: ["How many \(.applicationName)"]             )         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
Replies
1
Boosts
0
Views
1.9k
Activity
Oct ’22
App Intents does not work with standalone watchOS
I am trying to create an appIntent for a standalone watchOS App but it never shows up in the shortcuts app on the watch. Works fine for an iPhone app. What am I missing here ? import AppIntents struct intenttest: AppIntent {     static var title: LocalizedStringResource = "intent "     func perform() async throws -> some IntentResult {         return .result()     } } struct LibraryAppShorcuts: AppShortcutsProvider {     @AppShortcutsBuilder static var appShortcuts: [AppShortcut] {         AppShortcut(intent: intenttest(),                     phrases: ["My something phrase in \(.applicationName)"])     } }
Replies
1
Boosts
1
Views
971
Activity
Oct ’22