App Intents

RSS for tag

Extend your app’s custom functionality to support system-level services, like Siri and the Shortcuts app.

Posts under App Intents tag

200 Posts

Post

Replies

Boosts

Views

Activity

Shortcuts: Invalid action metadata
I have a habit tracker app that uses App Intents and Shortcuts. The app uses SwiftData to persist data, just in case that's important. One of the shortcuts serves to log habits. However, when the app has been in the background for a good while (over an hour or so), that particular shortcut always fails when I try to run it in the Shortcuts app with the system error "Invalid action metadata" caused by "a bug in the host app". The app has a total of 9 shortcuts, and it's just this one particular shortcut that seems to be failing – the others continue to run without any issues even after the app has been in the background for a long time. The app intent/shortcut that is problematic is the one called HabitEntryAppIntent. For example purposes, I've also included one of the non-problematic intents in the code snippet below called HabitEntryCounterForTodayAppIntent. Both of these intents have one @Parameter value of type HabitEntity. I'll post code snippets in the replies because the character limit is not large enough to include them here, or view them in this GitHub gist: Code snippets on GitHub I've tried everything I can think of whilst debugging, but none of the following fixed the error: Removed all usage of @MainActor and mainContext by replacing the ModelContext used in perform() with a locally created property. Removed all usage of static shared properties like Calendar.shared and ModelContainer.shared and replaced them with local properties. Removed all non-essential code such as the code for context.undoManager and WidgetManager.shared.reload(.all) and really striped it all down to the absolute essentials. Reduced the number of shortcut phrases in the problematic shortcut because there was perhaps too many (>10) originally. You might have noticed that the perform() method in the problematic intent manipulates the database whilst the non-problematic intent only reads the database. Given that the two intents in the snippet above both have the same @Property(...) var habitEntity: HabitEntity values, I tried to swap the contents of the perform() methods over to see what would happen. And here's what's strange: When the perform() method from the problematic HabitEntryAppIntent is used in HabitEntryCounterForTodayAppIntent, it works without any issues and successfully logs habits! And then when the perform() method from the non-problematic HabitEntryCounterForTodayAppIntent is used in HabitEntryAppIntent it fails with the system error "Invalid action metadata". This suggests that the problem is not in the code that logs the habit entries but rather something is wrong with HabitEntryAppIntent itself. I also tried changing the metadata used in HabitEntryAppIntent and its shortcut. I copied all the metadata used in HabitEntryCounterForTodayAppIntent (the title, description, parameterSummary etc) and pasted it into HabitEntryAppIntent. And did the same with the metadata in the shortcut (phrases, shortTitle etc) so that all the metadata used in HabitEntryAppIntent matched that used in HabitEntryCounterForTodayAppIntent. However, the shortcut for HabitEntryAppIntent continued to fail. Thus, it doesn't seem to be an issue with the code in perform() because that code succeeds when used in another app intent. And, despite the "metadata" error message, it doesn't seem to be an issue with the metadata in the app intent because I've tried using metadata from the non-problematic intent but it still fails. I have watched all WWDC videos related to app intents and shortcuts, and looked through the developer forum for similar questions, but I'm completely stumped by this issue and why it's only affecting one of my shortcuts. Also worth mentioning is that the widgets in the app that log habits using the same app intent do not suffer the same issue; they continue to work even after the Shortcut has failed. Moreover, if I try running the problematic shortcut for HabitEntryAppIntent and see the system error message, then run the shortcut for HabitEntryCounterForTodayAppIntent (which always succeeds), and then try running the HabitEntryAppIntent shortcut again, it then runs successfully on the second attempt. It seems that running HabitEntryCounterForTodayAppIntent fixes the issue, at least temporarily.
2
0
124
May ’25
Unable to install iOS & watchOS app to iPhone, because of intents change
I've been happily building and deploying my app to my iPhone and Watch S8, and the app was ready to submit to App Store Connect last night. However, when archiving it I got an error saying that my DynamicEventSelectionIntent was in multiple extensions. It was, kind of. When I started working on the complications I copied the Widgets intents into the complications, and left the name the same, but they were not in multiple targets. It looks like the info plist only had one item in the IntentsSupported (because they're the same name), so I decided to rename them so I had a widget one and a complications one. The problem I have now is that I can't deploy to my iPhone and Watch anymore because I'm getting this error: This app contains a WatchKit app with one or more Siri Intents app extensions that declare IntentsSupported that are not declared in any of the companion app's Siri Intents app extensions. WatchKit Siri Intents extensions' IntentsSupported values must be a subset of the companion app's Siri Intents extensions' IntentsSupported values. All I've done is rename one intent, and locate every instance of it in the info plist files, and add the appropriate new one into the right places. Here's what I've got. Main App contains Widget and WidgetIntentHandler, plus Watch App, which contains Complications and ComplicationsIntentHandler. Target: Main app: (I've removed everything that has no bearing on extensions.) Target: Widget: Target: WidgetIntentHandler: Target: Watch App: Target: Complications: Target: ComplicationsIntentHandler: Please, can someone tell me what should and should not be in the various parts, as I've tried for 12 hours now and I cannot get this to deploy to my iPhone anymore :( Thanks.
12
1
2.3k
May ’25
Does INIntent no longer work on macOS? Can't get shortcut to show up in Shortcuts app
Was going to add a shortcut to an app via INIntent. I followed the WWDC developer.apple.com/videos/play/wwdc2021/10232/?time=986 Steps: Created a .intentdefinition file and created an intent. Added the intent to .intentdefinition and compiled the app. Import the header file for the custom intent in the AppDelegate MyIntentname.h Have the AppDelegate conform to the protocol created in the generated code. Implement: -application:handlerForIntent: and return self (the app delegate) Run the app. Open the Shortcuts app and search for the 'shortcut' (according to the WWDC video linked above it should show up in the actions list). Doesn't show up in the list. I tried moving the build application out from Debug to my Applications folder to see if that would help the Shortcuts app find it, but it didn't. Am I missing a step/doing something wrong?
2
0
85
May ’25
Using App Intents in Live Activity to Pause a Timer
Hello, I am trying to test a concept of a timer stopwatch with Live Activities and integrating buttons like Pause/Resume. When the stopwatch starts, a new Live Activity is created. The stopwatch is managed by the ViewModel, which has functions like start(), pause(), resume(), reset(), and also startLiveActivity(), etc. It uses @AppStorage to store keys like stopWatchModeRaw values, startTimeInterval, etc. The Live Activity state is stored here in the view model using: private var currentActivity: Activity? = nil The Live Activity is started using: private func startActivity() async { guard currentActivity == nil, Activity<StopwatchAttributes>.activities.isEmpty else { if currentActivity == nil { findAndAssignExistingActivity() await updateActivity() } return } let attributes = StopwatchAttributes() let state = StopwatchAttributes.ContentState( .... pass in the content state variables .... ) let content = ActivityContent(state: state, staleDate: nil) do { let activity = try Activity<StopwatchAttributes>.request( attributes: attributes, content: content, pushType: nil ) // Store the activity instance self.currentActivity = activity } catch { print("Error requesting Live Activity: \(error.localizedDescription)") } } and FindAndAssignExistingAcivity does: private func findAndAssignExistingActivity() { if let existingActivity = findActivity(), existingActivity.activityState == .active || existingActivity.activityState == .stale { print("Found existing activity on launch: \(existingActivity.id)") self.currentActivity = existingActivity } else { print("No existing activity found on launch.") self.currentActivity = nil } } UpdateActivity if the activity exists with a guard statement, and then update the activity. This is also used when the user taps Pause in the Stopwatch. The main issue I am facing is with the PauseIntent, it can't find the Live Activity and will always exit at that guard statement. struct PauseIntent: AppIntent { static var title: LocalizedStringResource = "Pause Stopwatch" func perform() async throws -> some IntentResult { guard let defaults = UserDefaults(suiteName: appGroupID) else { return .result() // Simple failure } let currentModeRaw = defaults.integer(forKey: "stopwatchModeRawValue") let currentMode = StopwatchMode(rawValue: currentModeRaw) ?? .reset let startTimeInterval = defaults.double(forKey: "startTimeInterval") // TimeInterval when current running segment started let accumulatedTime = defaults.double(forKey: "accumulatedTime") guard let activity = Activity<StopwatchAttributes>.activities.first else { Self.logger.error("PauseIntent EXIT: No Live Activity found to update. (Activity<StopwatchAttributes>.activities is empty)") return .result() // EXITING HERE, No Live Activity Found, there was nothing found to update... -> It always exits here } followed by rest of the code to update the state of the live activity, but it never executes because the activity = Activity.activities.first always returns false. What seems to be the issue? 1 .Is the method wrong to check for the live activity before attempting to Pause? 2. Can the Live Activity actually Pause the Stopwatch Timer in the main App since the Live Activity is actually a Widget Extension and not the App itself, so it cannot see the data directly?
1
0
75
May ’25
Siri Intent - Car Commands
Hi Community, I'm new on Siri intents and I'm trying to introduce into my App a Siri Intent for Car Commands. The objective is to list into the Apple Maps the Car list of my App. Currently I've created my own target with its corresponding IntentHandlings, but in the .intentdefinition file of my App, I'm not able to find the List Car Intent. https://developer.apple.com/documentation/sirikit/car-commands Do I need some auth? Also I share my info.plist from the IntentExtension. Thank you very much, David.
0
0
63
May ’25
App Shortcuts Preview: No Matching Intent?
Hi! In neither Xcode 16.2 beta 3 nor Xcode 16.2 I am able to get App Shortcuts Preview to recognise my Shortcuts. In either supported language I always get "No Matching Intent" as the result. Flexible matching is enabled, minimum deployment target is iOS 18. The Shortcut phrases do work in the simulator and on device. Is this a known issue or am I missing something?
8
1
599
Apr ’25
Use Siri to control parts of my CarPlay app
I am building a CarPlay navigation app and I would like it to be as hands free as possible. I need a better understanding of how Siri can work with CarPlay and if the direction I need to go is using Intents or App Shortcuts. My goal is to be able to have the user speak to Siri and do things like "open settings" or "zoom in map" and then call a func in my app to do what the user is asking. Does CarPlay support this? Do I need to use App Intents or App Shortcuts or something else?
2
0
78
Apr ’25
Help getting elements from SwiftData in AppIntent for widget
Hello, I am trying to get the elements from my SwiftData databse in the configuration for my widget. The SwiftData model is the following one: @Model class CountdownEvent { @Attribute(.unique) var id: UUID var title: String var date: Date @Attribute(.externalStorage) var image: Data init(id: UUID, title: String, date: Date, image: Data) { self.id = id self.title = title self.date = date self.image = image } } And, so far, I have tried the following thing: AppIntent.swift struct ConfigurationAppIntent: WidgetConfigurationIntent { static var title: LocalizedStringResource { "Configuration" } static var description: IntentDescription { "This is an example widget." } // An example configurable parameter. @Parameter(title: "Countdown") var countdown: CountdownEntity? } Countdowns.swift, this is the file with the widget view struct Provider: AppIntentTimelineProvider { func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date(), configuration: ConfigurationAppIntent()) } func snapshot(for configuration: ConfigurationAppIntent, in context: Context) async -> SimpleEntry { SimpleEntry(date: Date(), configuration: configuration) } func timeline(for configuration: ConfigurationAppIntent, in context: Context) async -> Timeline<SimpleEntry> { var entries: [SimpleEntry] = [] // Generate a timeline consisting of five entries an hour apart, starting from the current date. let currentDate = Date() for hourOffset in 0 ..< 5 { let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! let entry = SimpleEntry(date: entryDate, configuration: configuration) entries.append(entry) } return Timeline(entries: entries, policy: .atEnd) } // func relevances() async -> WidgetRelevances<ConfigurationAppIntent> { // // Generate a list containing the contexts this widget is relevant in. // } } struct SimpleEntry: TimelineEntry { let date: Date let configuration: ConfigurationAppIntent } struct CountdownsEntryView : View { var entry: Provider.Entry var body: some View { VStack { Text("Time:") Text(entry.date, style: .time) Text("Title:") Text(entry.configuration.countdown?.title ?? "Default") } } } struct Countdowns: Widget { let kind: String = "Countdowns" var body: some WidgetConfiguration { AppIntentConfiguration(kind: kind, intent: ConfigurationAppIntent.self, provider: Provider()) { entry in CountdownsEntryView(entry: entry) .containerBackground(.fill.tertiary, for: .widget) } } } CountdownEntity.swift, the file for the AppEntity and EntityQuery structs struct CountdownEntity: AppEntity, Identifiable { var id: UUID var title: String var date: Date var image: Data var displayRepresentation: DisplayRepresentation { DisplayRepresentation(title: "\(title)") } static var defaultQuery = CountdownQuery() static var typeDisplayRepresentation: TypeDisplayRepresentation = "Countdown" init(id: UUID, title: String, date: Date, image: Data) { self.id = id self.title = title self.date = date self.image = image } init(id: UUID, title: String, date: Date) { self.id = id self.title = title self.date = date self.image = Data() } init(countdown: CountdownEvent) { self.id = countdown.id self.title = countdown.title self.date = countdown.date self.image = countdown.image } } struct CountdownQuery: EntityQuery { typealias Entity = CountdownEntity static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Countdown Event") static var defaultQuery = CountdownQuery() @Environment(\.modelContext) private var modelContext // Warning here: Stored property '_modelContext' of 'Sendable'-conforming struct 'CountdownQuery' has non-sendable type 'Environment<ModelContext>'; this is an error in the Swift 6 language mode func entities(for identifiers: [UUID]) async throws -> [CountdownEntity] { let countdownEvents = getAllEvents(modelContext: modelContext) return countdownEvents.map { event in return CountdownEntity(id: event.id, title: event.title, date: event.date, image: event.image) } } func suggestedEntities() async throws -> [CountdownEntity] { // Return some suggested entities or an empty array return [] } } CountdownsManager.swift, this one just has the function that gets the array of countdowns func getAllEvents(modelContext: ModelContext) -> [CountdownEvent] { let descriptor = FetchDescriptor<CountdownEvent>() do { let allEvents = try modelContext.fetch(descriptor) return allEvents } catch { print("Error fetching events: \(error)") return [] } } I have installed it in my phone and when I try to edit the widget, it doesn't show me any of the elements I have created in the app, just a loading dropdown for half a second: What am I missing here?
0
0
71
Apr ’25
Disambiguation for .system.search AppIntent
I'd like to display a list of items to disambiguate for a fulltext search intent. Using the Apple AppIntentsSampleApp, I added TrailSearch.swift: import AppIntents @AssistantIntent(schema: .system.search) struct TrailSearch: AppIntent { static let title: LocalizedStringResource = "Search Trail" static let description = IntentDescription("Search trail by name.", categoryName: "Discover", resultValueName: "Trail") @Parameter(title: "Trail") var criteria: StringSearchCriteria func perform() async throws -> some IntentResult & ReturnsValue<TrailEntity> { if criteria.term.isEmpty { throw $criteria.needsValueError(IntentDialog("need value")) } let trails = TrailDataManager.shared.trails { trail in trail.name.contains(criteria.term) } if trails.count > 1 { throw $criteria.needsDisambiguationError(among: trails.map { StringSearchCriteria(term: $0.name) }) } else if let firstTrail = trails.first { return .result(value: TrailEntity(trail: firstTrail)) } throw $criteria.needsValueError(IntentDialog("Nothing found")) } } Now when I type "trail" which matches several trails and thus lets us enter the disambiguation code path, the Shortcut app just displays the dialog title but no disambiguation items to pick from. Is this by design or a bug? (filed as FB17412220)
0
0
50
Apr ’25
Siri Shortcuts of Siri Intent to Voice Control Parts of App
I am new to the idea of Siri Shortcuts and App Intents. What I want to do is use Siri to run a function in my app. Such as saying to Siri Zoom in map and that will then call a function in my app where I can zoom in the map. Similarly, I could say Zoom out map and it would call a function to zoom out my map. I do not need to share any sort of shortcut with the Shortcuts app. Can someone please point me in the right direction for what type of intents I need to use for this?
0
0
53
Apr ’25
Parameter recognition on AppShortcuts invocation not consistent
While playing around with AppShortcuts I've been encountering some problems around getting the invocation phrase detected and/or the parameter get recognized after invocation phrase via Siri. I've found some solutions or explanations here in other posts (Siri not recognizing the parameter in the phrase & Inform iOS about AppShortcutsProvider), but I still have one issue and it's about consistency. For context, I've defined the parameter to be an AppEntity with it's respective query conforming to the EntityStringQuery Protocol in order to be able to fetch entities with the string given by Siri struct AnIntent: AppIntent { // other parts hidden for clarity @Parameter var entity: ModelEntity } For an invocation phrase akin to "Do something with in ", if the user uses the phrase with a entity previously donated via suggestedEntities() the AppShortcut get executed without problems. If the user uses a phrase with no parameter, like "do something with ", if the user gets asked to input the missing parameter and inputs one, it may or may not get recognized and be asked to input a parameter again, like in a loop. This happens even if the parameter given is one that was donated. I've found that when this happens the entities(matching string: String) function in the EntityQuery doesn't get called. The input can be of one word or sometimes two and it will not be called. So in other words entities(matching string: String) does not get called on every user parameter input Is this behavior correct? Do parameters have some restrictions on length or anything? Does Siri shows the user suggested entities when asked for entity input? It doesn't on my end. Additional question related to AppShortcuts: On AppShortcut definition, where the summary inside the parameter presentation is used? I see that it was defined in the AppIntentsSampleApp for the GetTrailInfo Intent but didn't find where it was used
0
0
56
Apr ’25
Dynamic parameters in shortcuts
I need to have a dynamic parameter for Shortcuts, so a person can say something like Hey Siri, order a pizza with The parameter code in the appIntent is @Parameter(title: "Title") var itemName: String In the Shortcut I use: AppShortcut( intent: NewItemIntent(), phrases: [ "order \(\.$itemName) using \(.applicationName)" ], shortTitle: "Order Item", systemImageName: "sparkles" ) When I call it "hey Siri, order pizza using ***" where pizza should be passed via the parameter then handed off to the appintent. However, it ignores the spoken parameter in lieu of putting up a dialog asking "What's the name?" I can say "pizza" and it now works. How can I pick up the parameter without having to go to that second step as the code implies?
5
0
170
Apr ’25
Duration type parameter in AppIntent
I'm developing an AppIntent with a Duration parameter, the definition looks like this: @Parameter(title: "Duration", description: "Time entry duration") var duration: Measurement<UnitDuration> When I run this AppIntent using Siri voice command (by a shortcut) the system asks for the duration value, however when I try to say "1 hour 10 minutes" the "hour" component is ignored, in the AppIntent's perform() method I see only the minutes set (so in this case only 10 minutes). Is there any way to use the Duration type for this type of natural language input? When I try to set only 10 minutues, or 1 hour separately it works, just the combination of these two fails. Thank you
3
0
70
Apr ’25
What is the correct syntax to continue in app for custom intent?
I have a custom intent. When my app is unable to complete the resolution of a parameter within the app extension, I need to be able to continue within the app. I am unable to figure out what the correct objective C syntax is to enable the execution to continue with the app. Here is what I have tried: completion([[PickWoodIntentResponse init] initWithCode:PickWoodIntentResponseCodeContinueInApp userActivity:nil]); This results in the following error: Implicit conversion from enumeration type 'enum PickWoodIntentResponseCode' to different enumeration type 'INAnswerCallIntentResponseCode' (aka 'enum INAnswerCallIntentResponseCode') I have no idea why it is referring to the enum type of 'INAnswerCallIntentResponseCode' which is unrelated to my app. I have also tried: PickWoodIntentResponse *response = [[PickWoodIntentResponse init] initWithCode:PickWoodIntentResponseCodeContinueInApp userActivity:nil]; completion(response); but that results in 2 errors: Implicit conversion from enumeration type 'enum PickWoodIntentResponseCode' to different enumeration type 'INAnswerCallIntentResponseCode' (aka 'enum INAnswerCallIntentResponseCode') and Incompatible pointer types passing 'PickWoodIntentResponse *' to parameter of type 'INStringResolutionResult *' The relevant autogenerated code provided to me with the creation of my intent is as follows: @class PickWoodIntentResponse; @protocol PickWoodIntentHandling <NSObject> - (void)resolveVarietyForPickWood:(PickWoodIntent *)intent withCompletion:(void (^)(INStringResolutionResult *resolutionResult))completion NS_SWIFT_NAME(resolveVariety(for:with:)) API_AVAILABLE(ios(13.0), macos(11.0), watchos(6.0)); @end typedef NS_ENUM(NSInteger, PickWoodIntentResponseCode) { PickWoodIntentResponseCodeUnspecified = 0, PickWoodIntentResponseCodeReady, PickWoodIntentResponseCodeContinueInApp, PickWoodIntentResponseCodeInProgress, PickWoodIntentResponseCodeSuccess, PickWoodIntentResponseCodeFailure, PickWoodIntentResponseCodeFailureRequiringAppLaunch } @interface PickWoodIntentResponse : INIntentResponse - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithCode:(PickWoodIntentResponseCode)code userActivity:(nullable NSUserActivity *)userActivity NS_DESIGNATED_INITIALIZER; @property (readonly, NS_NONATOMIC_IOSONLY) PickWoodIntentResponseCode code; @end Am I overlooking something? What would be the proper syntax to have within the completion block to satisfy the compiler?
1
0
80
Apr ’25
Can NWBrowser be used in an AppIntent extension? NoAuth
I have an iOS app that connects to a server running on macOS by leveraging NWListener & NWBrowser. It also makes use of the peerToPeer functionality / AWDL offered via the Network framework. This works great in the iOS app. Now I would like to add support for Shortcuts / App Intents in general. The NWConnection on its own is also working great in the App Intent, but only if I provide the host/port manually, which means I can't use the peer to peer functionality. If I try to run my NWBrowser in the AppIntent it immediately changes its state to failed with a NoAuth (-65555) error: nw_browser_cancel [B1517] The browser has already been cancelled, ignoring nw_browser_cancel(). nw_browser_fail_on_dns_error_locked [B1518] DNSServiceBrowse failed: NoAuth(-65555) NWClientManager: Browser failed: -65555: NoAuth I haven't found documentation/information on whether NWBrowser should work in an AppIntent extension or not.
1
0
65
Apr ’25
Improving references to localized strings in App Intents
In order to make referencing keys for localized strings a little more reliable, our application references generated constants for localized string keys: This eliminates the potential for developers to misspell a key when referencing a localized strings. And because these constants are automatically generated by the exact same process that provides localized strings for the application, each and every constant is guaranteed to have a localized string associated with it. I’m currently attempting to implement something similar for the localized strings referenced by our new App Intents. Our initial release of App Intent functionality is simply using string literals to reference localized strings: However, I am running into several issues when trying to reference the string keys as a constant. The closest I managed to get was defining the constant as either a LocalizationValue or as a StaticString and referencing the constant while initializing the LocalizedStringResource. With this approach, I see no errors from Xcode until I try and compile. What’s more is that the wording of the error being thrown is quite peculiar: As you can see with the sample code above, I am clearly calling LocalizedStringResource’s initializer directly as Indicated by the error. Is what I’m trying to do even possible with App Intents? From my research, it does look like iOS app localization is moving more towards using string literals for localized strings. Like with String Catalog’s ability to automatically generate entries from strings referenced in UI without the need for a key. However, we’d prefer to use constants if possible for the reasons listed above.
0
0
82
Apr ’25
Interactive Live Activity Bug in iOS 18 - perform not called
In iOS 18 (beta 1-4) when you set openAppWhenRun = false in your AppIntent of your live activity the perform function never gets called. In iOS 16 and 17 my live activities work. I have downloaded other apps and in their live activities any button tab which doesn´t open the app is also doing nothing in iOS 18. Has anyone got this working? Any comments from an Apple engineer on this?
4
2
1.3k
Apr ’25