I am trying to write a unit test for an AppIntent and override the AppDependencyManager so I can inject dependencies for the purposes of testing. When I run a test, the app crashes with:
AppIntents/AppDependencyManager.swift:120: Fatal error: AppDependency of type Int.Type was not initialized prior to access. Dependency values can only be accessed inside of the intent perform flow and within types conforming to _SupportsAppDependencies unless the value of the dependency is manually set prior to access.
App Intent:
import AppIntents
struct TestAppIntent: AppIntent {
@AppDependency var count: Int
static var title: LocalizedStringResource { "Test App Intent "}
func perform() async throws -> some IntentResult {
print("\(count)")
return .result()
}
}
extension TestAppIntent {
init(dependencyManager: AppDependencyManager) {
_count = AppDependency(manager: dependencyManager)
}
}
Unit Test
import Testing
import AppIntents
@testable import AppIntentTesting
struct TestAppIntentTests {
@Test("test")
func test() async throws {
let dependencyManager = AppDependencyManager()
dependencyManager.add(dependency: 5)
let appIntent = TestAppIntent(dependencyManager: dependencyManager)
_ = try await appIntent.perform()
}
}
App Intents
RSS for tagExtend your app’s custom functionality to support system-level services, like Siri and the Shortcuts app.
Posts under App Intents tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi! I am using the Automations in shortcuts in macOS 26 dev beta 1 and I have all my shortcuts working except this one. Why?(photo included). All the others are very similar except they do other things not make pdf. They work. Why does this one not. I tried changing the extension to .doc, or .docx instead of doc and docx I tried using if name ends in .docx I tried file filtering nothing. Any ideas? Thanks!
When I import both AppIntents and MediaPlayer in the same file, I get the error “No such module '_MediaPlayer_AppIntents’”
To reproduce:
Create a new project with Xcode 26 beta, selecting storyboard UI and swift language.
In ViewController.swift add import AppIntents and import MediaPlayer
Build
Get the error: “No such module '_MediaPlayer_AppIntents’”
Submitted as FB18189693
New features in WatchOS 26 with configurable widgets make it more important than ever that apps adopt IntentConfiguration options where applicable.
I develop an app with an Apple Watch complication/widget on many many user's Watch faces around the world. I've completed updating my code to support WidgetKit and remove ClockKit.
However, I face huge issues adding support for users to configure their widget/complications.
If I update a widget to go from StaticConfiguration to IntentConfiguration, even when keeping the "kind" string the same, the widget disappears from the Watch face.
This is an unacceptable user experience meaning I can't proceed with the migration. The problem is users will expect me to offer configuration in the Watch face soon for their widget/complication. Currently this process is done in a sub-optimal way in the app itself.
A similar issue exists on iOS where the widget will just "freeze" indefinitely is migrated.
This issue still occurs on the iOS 26 and WatchOS 26 betas.
So how to move this forward.
This has been discussed previously here: https://developer.apple.com/forums/thread/661247
I've mentioned it at WidgetKit labs
I've filed feedback last year: FB13880020
I've filed feedback this year: FB18180368
It seems really important this gets fixed for developers to adopt these new features, is there any other migration route I'm missing or a workaround that would mitigate this seemingly big problem.
My app uses App Intents to create App Shortcuts.
When I build and run my app in Xcode, the App Shortcuts Preview tool (under Product menu) shows the following message:
No Flexible Matching Assets
This target is for a platform which is not supported by Flexible Matching or does not have Flexible Matching enabled.
All of my project's targets are iPhone only with a minimum deployment of 18.0. In the build settings for this project, Enable App Shortcuts Flexible Matching is set to Yes. (build settings reference)
Any guidance on how to troubleshoot this? Thank you!
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags:
Xcode
Siri and Voice
Shortcuts
App Intents
Hey everyone,
I have an issue I'm running into – maybe someone has the expertise to help!
I've created an app that adds Intents to the Shortcuts app, to interact with S3-compatible object storage. Everything works fine, until you decide to upload/download a large file, that your internet connection cannot handle in the ~30-second intent timeout.
I've explored uploading files with a background task which seems to work somehow, but the bigger issue would be downloading larger files, as other parts of the subsequent shortcut may rely on it.
To the question: Is there some way of increasing the timeout for a shortcuts intent, or a way to "trick" shortcuts into letting my custom intents download/upload files without timing out?
Thanks so much!
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags:
Shortcuts
Background Tasks
Intents
App Intents
I have an app that lets you create cars. I have a CarEntity, an OpenCarIntent, and a CreateCarIntent. I want to support the Open When Run option when creating a car. I understand to do this, you just update the return type of your perform function to include & OpensIntent, then change your return value to include opensIntent: OpenCarIntent(target: carEntity). When I do this, I get a compile-time error:
Cannot convert value of type 'CarEntity' to expected argument type 'IntentParameter<CarEntity>'
What am I doing wrong here?
struct CreateCarIntent: ForegroundContinuableIntent {
static let title: LocalizedStringResource = "Create Car"
@Parameter(title: "Name")
var name: String
@MainActor
func perform() async throws -> some IntentResult & ReturnsValue<CarEntity> & OpensIntent {
let managedObjectContext = PersistenceController.shared.container.viewContext
let car = Car(context: managedObjectContext)
car.name = name
try await managedObjectContext.perform {
try managedObjectContext.save()
}
let carEntity = CarEntity(car: car)
return .result(
value: carEntity,
opensIntent: OpenCarIntent(target: carEntity) // FIXME: Won't compile
)
}
}
struct OpenCarIntent: OpenIntent {
static let title: LocalizedStringResource = "Open Car"
@Parameter(title: "Car")
var target: CarEntity
@MainActor
func perform() async throws -> some IntentResult {
await UIApplication.shared.open(URL(string: "carapp://cars/view?id=\(target.id)")!)
return .result()
}
}
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags:
iOS
Shortcuts
Intents
App Intents
In WatchOS 26 you can now configure Apple Watch Widgets that use AppIntents instead of having a preconfigured option via AppIntentRecommendation.
This is demonstrated in the Weather Details Widget. In that, the Intent has been set up such that the options have icons for each parameter.
How can I update my Intent code to offer this?
struct DataPointsWidgetIntent: AppIntent, WidgetConfigurationIntent {
static var title: LocalizedStringResource = "Data Points Widget Configuration"
static var description = IntentDescription("Configure the individual data point display for Widgets.")
static var isDiscoverable: Bool { return false}
init() {}
func perform() async throws -> some IntentResult {
print("DataPointsWidgetIntent perform")
return .result()
}
@Parameter(title: "Show Individual Data Points", default: true)
var showDataPoints: Bool?
@Parameter(title: "Trend Timescale", default: .week)
var timescale: TimescaleTypeAppEnum?
static var parameterSummary: some ParameterSummary {
Summary("Test Info") {
\.$showDataPoints
\.$timescale
}
}
}
enum TimescaleTypeAppEnum: String, AppEnum {
case week
case fortnight
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Trend Timescale")
static var caseDisplayRepresentations: [Self: DisplayRepresentation] = [
.week: "Past Week",
.fortnight: "Past Fortnight"
]
}
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
WidgetKit
Intents
WeatherKit
App Intents
Add NSUserActiveTypes ->INSendMessage Intent to info. plist. Starting the app on watchos will handoff Outlook on Mac? Normal on iOS.
getting an interesting error attempting to compile my app in Xcode 26 beta.
error: Unable to find module dependency: '_MediaPlayer_AppIntents' (in target 'icatcher' from project 'icatcher')
note: A dependency of main module 'MainModuleCrossImportOverlays' (in target 'icatcher' from project 'icatcher')
Unable to find module dependency: '_MediaPlayer_AppIntents'
Not sure what to try and pull to fix this issue
Hi Apple team,
When using AppShortcutsProvider, I hit the hard limit:
Each app may have at most 10 App Shortcuts.
This feels limiting for apps that offer multiple workflows and would benefit from deeper Siri integration.
Could this cap be raised — ideally to 30 — to support broader use of AppIntents, enhance Siri automation, and unlock more system-level capabilities?
AppShortcuts are a fantastic tool. Increasing the limit would make them even more powerful.
Thanks!
Topic:
Machine Learning & AI
SubTopic:
Apple Intelligence
Tags:
Shortcuts
App Intents
Apple Intelligence
I'm developing an iOS app that uses Siri Shortcuts to enhance the user experience. Currently, I have implemented functionality that allows users to perform certain actions via Siri Shortcuts.
My team wants to improve the user experience by giving an instructional audio prompt (e.g., "say 'hey Siri [action name]' if you want to [perform action]") to users. However, we want to ensure this prompt is only played when the user has already enabled Siri Shortcuts.
The challenge is determining whether Siri Shortcuts are properly enabled before suggesting their use. We want to avoid situations where users follow our audio instructions to use Siri, only to discover that Siri Shortcuts aren't properly configured on their device.
Since we're using Siri Shortcuts for this feature, the standard requestSiriAuthorization(_:) method doesn't apply to our use case(It said You don’t need to request authorization if your app only supports actions in the Shortcuts app. in https://developer.apple.com/documentation/sirikit/requesting-authorization-to-use-siri).
What is the recommended approach to verify that Siri Shortcuts are properly enabled before prompting users to interact with them? Is there a reliable way to check this status(should be the bool value of the toggle in the pic below) programmatically?
Thank you for your assistance.
Hello,
We are reaching out to the official forum as an option to help us solve an issue we’re encountering with our app.
The problem lies in the implementation of the AppIntents framework in our codebase, which, at the moment, is impossible to complete due to compilation errors occurring in specific targets of our app. We are currently using Xcode 16.0.
First of all, we want to clarify that the integration of the AppIntents library poses no issues in our development targets (pre-production environments), since no additional code obfuscation steps are performed there.
However, in the release targets used for production builds (those intended to be released to users), we encounter the following compilation error:
These errors indicate that the “.swiftconstvalues” files are missing for all of the files in our application.
We also want to highlight that we are using a code obfuscation tool called Arxan, provided by Digital.ai. This tool is integrated via specific Build Settings configurations, various files added to the project, and an additional Build Phase script.
We have conducted the following tests:
Disabling Arxan in release targets: The app compiles successfully and those files are generated (suspicious, I know).
Adding a library with AppIntents references and an AppIntent in our app: Both scenarios produce the same compilation error.
Creating a demo project with AppIntents and Arxan (basic implementation): The project compiles correctly and those files are in place.
Contacting Digital.ai support: They suggested several changes to the Build Settings, but none of them resolved the issue.
Additionally, we’ve attempted to gather information from the compiler to understand how these “.swiftconstvalues” files are generated. Unfortunately, we haven’t found any official documentation, so we would like to ask a few questions:
Is it possible to interfere with the creation of these files in any way? For example, via scripts or other custom build steps?
Is there any way to force the generation of these files through a build parameter or flag?
Is it possible to bypass the “Extract App Intents Metadata” step during compilation? If so, what would be the implications of doing this when using a library that includes references to AppIntents?
I know that involving a code obfuscation tool raises suspicions about it being the problem, we just want to know a little more about this compilation step to have some more context before reaching them again.
Feel free to ask any questions or details, any reply is appreciated.
Thanks
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Developer Tools
Compiler
Intents
App Intents
I asked a question similar to this earlier, but I think this is probably the better question.
I have a food-ordering app. When the user wants to pick up food, I'd like for Apple Maps to automatically display the location of the restaurant that the user is driving to.
Calendar does something similar. If there is an event that is soon, the location in the calendar-event shows up in Apple Maps. I'd like to do the same thing.
So, when the user makes an order, they'll need to drive to the location fairly quickly. So, I'd like to launch Apple Maps, see the location of the restaurant where I'm picking up food, and then get directions to it. Bonus points if this also works when I have CarPlay.
I am using live activity in my app. Functionality is start, update & end events are started from the server. There is one interaction button added using app intent in live activity widget. That button needs to update widget ui locally using activity kit.
Issue is when os receives first start event push then update ui works fine and reflecting on live activity widget but when update notification receives by os after 1 mins then action button stops updating the ui locally.
Can anyone please add some suggestions to fix this.
I’m working with AppIntents and AppEntity to integrate my app’s data model into Shortcuts and Siri. In the example below, I define a custom FoodEntity and use it as a @Parameter in an AppIntent. I’m providing dynamic options for this parameter via an optionsProvider.
In the Shortcuts app, everything works as expected: when the user runs the shortcut, they get a list of food options (from the dynamic provider) to select from.
However, in Siri, the experience is different. Instead of showing the list of options, Siri asks the user to say the name of the food, and then tries to match it using EntityStringQuery.
I originally assumed this might be a design decision to allow hands-free use with voice, but I found that if you use an AppEnum instead, Siri does present a tappable list of options. So now I’m wondering: why the difference?
Is there a way to get the @Parameter with AppEntity + optionsProvider to show a tappable list in Siri like it does in Shortcuts or with an AppEnum?
Any clarification on how EntityQuery.suggestedEntities() and DynamicOptionsProvider interact with Siri would be appreciated!
struct CaloriesShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: AddCaloriesInteractive(),
phrases: [
"Add to \(.applicationName)"
],
shortTitle: "Calories",
systemImageName: "fork"
)
}
}
struct AddCaloriesInteractive: AppIntent {
static var title: LocalizedStringResource = "Add to calories log"
static var description = IntentDescription("Add Calories using Shortcuts.")
static var openAppWhenRun: Bool = false
static var parameterSummary: some ParameterSummary {
Summary("Calorie Entry SUMMARY")
}
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(stringLiteral:"Add to calorie log")
}
@Dependency
private var persistenceManager: PersistenceManager
@Parameter(title: LocalizedStringResource("Food"), optionsProvider: FoodEntityOptions())
var foodEntity: FoodEntity
@MainActor
func perform() async throws -> some IntentResult & ProvidesDialog {
return .result(dialog: .init("Added \(foodEntity.name) to calorie log"))
}
}
struct FoodEntity: AppEntity {
static var defaultQuery = FoodEntityQuery()
@Property var name: String
@Property var calories: Int
init(name: String, calories: Int) {
self.name = name
self.calories = calories
}
static var typeDisplayRepresentation: TypeDisplayRepresentation {
TypeDisplayRepresentation(name: "Calorie Entry")
}
static var typeDisplayName: LocalizedStringResource = "Calorie Entry"
var displayRepresentation: AppIntents.DisplayRepresentation {
DisplayRepresentation(title: .init(stringLiteral: name), subtitle: "\(calories)")
}
var id: String {
return name
}
}
struct FoodEntityQuery: EntityQuery {
func entities(for identifiers: [FoodEntity.ID]) async throws -> [FoodEntity] {
var result = [FoodEntity]()
for identifier in identifiers {
if let entity = FoodDatabase.allEntities().first(where: { $0.id == identifier }) {
result.append(entity)
}
}
return result
}
func suggestedEntities() async throws -> [FoodEntity] {
return FoodDatabase.allEntities()
}
}
extension FoodEntityQuery: EntityStringQuery {
func entities(matching string: String) async throws -> [FoodEntity] {
return FoodDatabase.allEntities().filter({$0.name.localizedCaseInsensitiveCompare(string) == .orderedSame})
}
}
struct FoodEntityOptions: DynamicOptionsProvider {
func results() async throws -> ItemCollection<FoodEntity> {
ItemCollection {
ItemSection("Section 1") {
for entry in FoodDatabase.allEntities() {
entry
}
}
}
}
}
struct FoodDatabase {
// Fake data
static func allEntities() -> [FoodEntity] {
[
FoodEntity(name: "Orange", calories: 2),
FoodEntity(name: "Banana", calories: 2)
]
}
}
I have an iOS app and that has CarPlay enabled. I have Siri capability and the feature has been tested in Car. The voice commands are working perfectly fine.
However, I am facing a weird issue as described below,
The key NSSiriUsageDescription, is set to custom text in info.plist. After generating archive, I exported and checked the package contents, in which the the key NSSiriUsageDescription was reset to default text(Describe why your app needs Siri access) in the info.plist.
I do not have any dynamic build process that's writing to the info.plist. Only the Siri key is being reset, rest of keys like camera/location permissions are intact.
Kindly suggest what needs to be done at my end
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Siri and Voice
App Intents
Organizer Window
Privacy
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.
I have a question about the app lifecycle when my app is launched via a Shortcut. I'm adding a INIntent to a Mac app. So my app delegate implements:
- (nullable id)application:(NSApplication *)application handlerForIntent:(INIntent *)intent
Then my custom intent handler implements the two protocol methods -confirmIntentNameHere:completion: and -handleIntentNameHere:completion:
During my testing -applicationDidFinishLaunching: is called before the intent methods, so I can forward methods to my main window controller to perform the shortcut actions, since it's already ready.
....But if this is not always the case, I can still perform them but I'd have to move the code out of the window controller to perform the action "headless" if invoked before my app has built its UI. Just wondering if this is something I should be prepared for.
Thanks in advance.
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?
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags:
Shortcuts
SiriKit
Intents
App Intents