hi so im trying to create a simple app that has two pressable buttons that turn a spa mode on and off wishing another app
so far I have the UI figured out the app works the only issue is right now when I press spa on I have setup so it opens Siri Shortcuts and enables the shortcut is there a way to make the app revert back to mine after the action is done? or is there another way to open the other app and navigate to the button within that app and enable it behind my app
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
Hello everyone,
I’m currently developing a Playground App for the Swift Student Challenge, and its core functionality relies heavily on Shortcuts Automation, App Shortcuts, and interactions with the Focus Mode status (e.g., reading Focus Status or execute Focus Filter).
Before finalizing my submission, I’d like to clarify whether these features will function as expected during the review process. Specifically:
Shortcuts Automation: My app uses custom shortcuts to trigger actions within the Playground. Will reviewers be able to test these shortcuts seamlessly, or do I need to provide explicit instructions for enabling/setting them up?
App Shortcuts: The app integrates system-level App Shortcuts (via App Intents). Are these supported in the test environment, and will reviewers see them during testing?
Focus Status Interaction: The app dynamically responds to changes in the device’s Focus Mode (e.g., adjusting UI and function based on FocusStatus). Does the evaluation environment allow access to Focus Status data, and are there restrictions on simulating Focus Mode changes?
I want to ensure these features are testable and don’t lead to unexpected issues during review. Any insights or advice from past participants, mentors, or Apple experts would be greatly appreciated!
Thank you in advance for your guidance!
Hi,
I’m trying to get an array of strings from the user using AppIntents, but I’m encountering an issue. The shortcut ends without prompting the user for input or saving the value, though it doesn’t crash. I need to get the user to input multiple tasks in an array, but the current approach isn’t working as expected.
Here’s the current method I’m using:
// Short code snippet showing the current method
private func collectTasks() async throws -> [String] {
var collectedTasks: [String] = tasks ?? []
while true {
if !collectedTasks.isEmpty {
let addMore = try await $input.requestConfirmation("Would you like to add another task?")
if !addMore {
break
}
}
let newTask = try await $input.requestValue("Please enter a task:")
collectedTasks.append(newTask)
}
return collectedTasks
}
The Call
func perform() async throws -> some IntentResult {
let finalTasks = try await collectTasks()
// Some more Code
}
Any advice or suggestions would be appreciated. Thanks in advance!
Hi everyone,
i'm trying to request in a AppIntent an array of strings. But I want to give the user the chance to add more than one String.
Yet, I do it so:
import AppIntent
struct AddHomework: AppIntent {
// some Parameters
@Parameter(title: "Tasks")
var tasks: [String]?
@Parameter(title: "New Task") //Only for the special request
var input: String?
private func collectTasks() async throws -> [String] {
var collectedTasks: [String] = tasks ?? []
while true {
if !collectedTasks.isEmpty {
let addMore = try await $input.requestConfirmation(for: "Möchtest du noch eine Aufgabe hinzufügen?")
if !addMore {
break
}
}
let newTask = try await $input.requestValue("Please enter your task:")
collectedTasks.append(newTask)
}
return collectedTasks
}
@MainActor
func perform() async throws -> some IntentResult {
let finalTasks = try await collectTasks()
// some more code
return .result()
}
}
But this is not working. The Shortcut is ending without requesting anything. But it is not crashing.
I would thankfully for some help.
(Public dupe of FB16477656)
The Shortcuts app allows you to parameterise the input for an action using variables or allowing "Ask every time". This option DOES NOT show when conforming my AppEntity.defaultQuery Struct to EntityStringQuery:
But it DOES shows when confirming to EntityQuery:
As discussed on this forum post (or FB13253161) my AppEntity.defaultQuery HAS TO confirm to EntityStringQuery to allow for searching by String from Siri Voice input.
To summarise:
With EntityQuery:
My Intent looks like it supports variables via the Shortcuts app. But will end up in an endless loop because there is no entities(matching string: String) function.
This will allow me to choose an item via the Shorcuts.app UI
With EntityStringQuery:
My Intent does not support variables via the Shortcuts app.
I am not allows to choose an item via the Shorcuts.app UI.
Even weirder, if i set up the shortcut with using a build with EntityQuery and then do another build with EntityStringQuery it works as expected.
Code:
/*
Works with Siri to find a match, doesn't show "Ask every time"
*/
public struct WidgetStationQuery: EntityStringQuery {
public init() { }
public func entities(matching string: String) async throws -> [Station] {
let stations = [Station(id: "car", name: "car"), Station(id: "bike", name: "bike")]
return stations.filter { $0.id.lowercased() == string.lowercased() }
}
public func entities(for identifiers: [Station.ID]) async throws -> [Station] {
let stations = [Station(id: "car", name: "car"), Station(id: "bike", name: "bike")]
return stations.filter { identifiers.contains($0.id.lowercased()) }
}
public func suggestedEntities() async throws -> [Station] {
return [Station(id: "car", name: "car"), Station(id: "bike", name: "bike")]
}
public func defaultResult() async -> Station? {
try? await suggestedEntities().first
}
}
/*
DOES NOT work with Siri to find a match, but Shortcuts shows "Ask every time"
*/
public struct WidgetBrokenStationQuery: EntityQuery {
public init() { }
public func entities(matching string: String) async throws -> [Station] {
let stations = [Station(id: "car", name: "car"), Station(id: "bike", name: "bike")]
return stations.filter { $0.id.lowercased() == string.lowercased() }
}
public func entities(for identifiers: [Station.ID]) async throws -> [Station] {
let stations = [Station(id: "car", name: "car"), Station(id: "bike", name: "bike")]
return stations.filter { identifiers.contains($0.id.lowercased()) }
}
public func suggestedEntities() async throws -> [Station] {
return [Station(id: "car", name: "car"), Station(id: "bike", name: "bike")]
}
public func defaultResult() async -> Station? {
try? await suggestedEntities().first
}
}```
I'm currently working on an AppIntent in my app to import Apple Pay transactions via Transaction triggers in Shortcuts. While I can access the transaction name with the following code:
@Parameter(title: "Transaction")
var transaction: String
I'm not sure how to retrieve the full details of the transaction, including:
Card or Pass
Merchant
Amount
Name
At the moment, transaction only provides the name as a string, but I need access to the complete transaction data. I know that by selecting specific fields like Amount, Merchant, etc., I can retrieve each piece of data individually, but it would be much easier and more user-friendly to simply retrieve the entire transaction object at once.
Has anyone successfully retrieved all details of an Apple Pay transaction in this context, and if so, could you share how to do so?
I've been stuck for days trying to figure out how to extract the full text of a Siri prompt that launches my app. We need to be able to get the text of the full command, such as "Hey siri, buy dogfood...." so I can get "dogfood" or anything else following 'buy' . The examples I am finding are a) out of date or b) incomplelete. Right now we're using AppIntents with Shortcuts, but have to use dedicated shortcuts for each specific purchase, which are obviously very limiting.
Xcode 16.2 are unavailable to develop widget with dynamic options, no matter SiriIntent or AppIntent that I try to use.
I have try to start a complete new project, then add widget with app intent checkbox check, with zero code changed then i press command run and WidgetKit Simulator present CHSErrorDomain error 1103 always, if i try to add widget directly from desktop, dynamic options are available to select but widgets doesn't seem like load successfully, it is stuck same in the WidgetKit Simulator.
I also try to start a new project in my other MacBook but no luck, this error are presenting all the time, I'm totally stuck here, does anybody having this issue?
I'm trying to create two widgets, widget A and B.
Currently A and B are very similar so they share the same Intent and Intent Timeline Provider.
I use the Intent Configuration interface to set a parameter, in this example lets say its the background tint.
On one of the widgets, widget A, I want to also set another String enum parameter (for a timescale), but I don't want this option to be there for widget B as it's not relevant.
I'm aware of some of the options for configuring the ParameterSummary, but none that let me pass in or inject the "kind" string (or widget ID) of the widget that's being modified.
I'll try to provide some code for examples.
My Widget Definition (targeting >= iOS 17)
struct WidgetA: Widget {
// I'd like to access this parameter within the intent
let kind: String = "WidgetA"
var body: some WidgetConfiguration {
AppIntentConfiguration(kind: kind, intent: WidgetIntent.self, provider: IntentTimelineProvider()) { entry in
WidgetView(data: entry)
}
.configurationDisplayName("Widget A")
.description("A widget.")
.supportedFamilies([.systemMedium, .systemLarge])
}
}
struct WidgetB: Widget {
let kind: String = "WidgetB"
var body: some WidgetConfiguration {
AppIntentConfiguration(kind: kind, intent: WidgetIntent.self, provider: IntentTimelineProvider()) { entry in
WidgetView(data: entry)
}
.configurationDisplayName("Widget B")
.description("B widget.")
.supportedFamilies([.systemMedium, .systemLarge])
}
}
struct IntentTimelineProvider: AppIntentTimelineProvider {
typealias Entry = WidgetIntentTimelineEntry
typealias Intent = WidgetIntent
........
}
struct WidgetIntent: AppIntent, WidgetConfigurationIntent {
// This intent allows configuration of the widget background
// This intent also allows for the widget to display interactive buttons for changing the Trend Type
static var title: LocalizedStringResource = "Widget Configuration"
static var description = IntentDescription("Description.")
static var isDiscoverable: Bool { return false}
init() {}
init(trend:String) {
self.trend = trend
}
// Used for implementing interactive Widget
func perform() async throws -> some IntentResult {
print("WidgetIntent perform \(trend)")
#if os(iOS)
WidgetState.setState(type: trend)
#endif
return .result()
}
@Parameter(title: "Trend Type", default: "Trend")
var trend:String
// I only want to show this parameter for Widget A and not Widget B
@Parameter(title: "Trend Timescale", default: .week)
var timescale: TimescaleTypeAppEnum?
@Parameter(title: "Background Tint", default: BackgroundTintTypeAppEnum.none)
var backgroundTint: BackgroundTintTypeAppEnum?
static var parameterSummary: some ParameterSummary {
// Summary("Test Info") {
// \.$timescale
// \.$backgroundTint
// }
// An example of a configurable widget parameter summary, but not based of kind/ID string
When(\.$backgroundTint, .equalTo, BackgroundTintTypeAppEnum.none) {
Summary("Test Info") {
\.$timescale
\.$backgroundTint
}
} otherwise : {
Summary("Test Info") {
\.$backgroundTint
}
}
}
}
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"
]
}
enum BackgroundTintTypeAppEnum: String, AppEnum {
case blue
case none
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Background Tint")
static var caseDisplayRepresentations: [Self: DisplayRepresentation] = [
.none: "None (Default)",
.blue: "Blue"
]
}
I know I could achieve what I'm after by having a separate Intent and separate IntentTimelineProvider for each widget. But this all seems unnessecary for just a simple optional parameter based on what widget its configuring.... unless I'm missing the point about Intents, Widgets or something!
I've done a fair bit of other searching but can't find an answer to this overall scenario.
Many thanks for any help.
not sure where to post this hence adding here.
how to run in this full screen mode even when the screen is locked. As far as I looked, it’s only live activities that the developers are made available with. Is there a way to create our own UI on lockscreen, given a similar usecase exists?
I’ve implemented an Intent Extension and added support for handling the INSendMessageIntent in the intent handler class.
Currently, this intent is automatically visible in the Shortcuts app by default. However, for security reasons (as it involves handling phone numbers), I want to restrict the use of this intent to Siri only and ensure it does not appear in the Shortcuts app.
Has anyone encountered this requirement before or knows a way to prevent the intent from appearing in the Shortcuts app, while still keeping it functional via Siri?
Looking forward to your suggestions!
Hi Devs,
I’ve created an app intent shortcut for our Best Buy app. This shortcut is visible on iOS 17.2 and later. However, I’ve marked it to support iOS 16+ as shown below:
import AppIntents
@available(iOS 16.0, *)
struct LaunchIntent: OpenIntent {
why we are not able to see shortcuts for iOS 16?
Hi, I am trying to understand how this mechanism integrates with shortcuts (and i guess siri + apple intelligence in near future) and other apps.
Basic setup is an AppEntity that implements 'transferable' and is returning a DataRepresentation of 'text'.
got an AppIntent returns a one of the 'entitities' and I'm simply trying to pass the result to initially email or another app using shortcuts. even with canned 'hello world' string being marshalled into DataRepresentation(.text) I am not seeing anything in usual system targets like email, messages, notes. It opens the app ok, but no text is present. (note: if I use an incorrect DataRepresentation type with email it'll flat out fail saying 'not correct 'text' type)
What exactly do I need to do here and is there any example code I can look at?
thanks
I've been exploring the Trails Sample App from this session at WWDC24.
The app has a TrailEntity of type AppEntity which is leveraged in multiple places throughout the app, including:
The GetTrailInfo App Intent with a trail parameter of type TrailEntity.
A parameterized App Shortcut which calls the GetTrailInfo intent.
The TrailDataManager's init calls updateSpotlightIndex(), which creates a CSSearchableItem for each Trail in the app, along with an associateAppEntity call linking the corresponding TrailEntity to each item that gets added to the CSSearchableIndex.
If you build the app and search "trails" in Spotlight, the Trails Sample App section includes instances of TrailEntity as search results. But if you comment out the App Shortcut that takes a TrailEntity as a parameter and rebuild, there are no instances of TrailEntity in the search results. In both cases, the console prints [Spotlight] Trails indexed by Spotlight.
Is this expected behavior? Why are the TrailEntity instances only appearing in Spotlight via the App Shortcut? Shouldn't the CSSearchableItem instances show up in Spotlight on their own regardless? If not, then what is the purpose of adopting Core Spotlight with App Entities? Does this add the app entities to the semantic index for "new Siri", even though they're not user facing in the Spotlight UI?
Hi everyone,
I have a simple question regarding App Intents. I have an intent that defines a few parameters, one of which is a Date. When the user is prompted for input, I’d like the date picker to start at a specific value (e.g., tomorrow) instead of the default current date.
Is there a way to set an initial/default value for the date parameter in an App Intent?
Thanks in advance for any guidance!
I have an App Intent that returns a MyEntity value with the following properties:
struct MyEntity: AppEntity {
@Property(title: "Title")
var title: String?
@Property(title: "Image")
var image: IntentFile?
}
I created a Shortcut that takes the output value of this intent and passes it as the input to the Send Message action. When I tap the MyEntity parameter in the message action, it shows to be of Type MyEntity. Below that, I can select 1 of 3 options: MyEntity, Title, or Image.
When I run the shortcut, a new message compose window appears with the following behavior depending on the selected option:
MyEntity - the message draft is empty
Title - the message draft shows the title string
Image - the message draft shows the image
My expected and desired result when MyEntity is selected would be a message draft populated with the image and the title string as text. How would I achieve this? Is it possible?
I've experimented with conforming MyEntity to Transferable. That's enabled use cases such as passing the MyEntity input as Type Image for example.
Do I need to create a custom UTType to represent MyEntity, or is that unrelated to my issue? I haven't explored this yet but seems potentially related!
In this thread, I asked about adding parameters to App Shortcuts. The conclusion that I've drawn so far is that for App Shortcuts, there cannot be any parameters in the prompt, otherwise the system cannot find the AppShortcutsProvider. While this is fine for Shortcuts and non-voice interaction, I'd like to find a way to add parameters to the prompt. Here is the scenario:
My app controls a device that displays some content on "pages." The pages are defined in an AppEnum, which I use for Shortcuts integration via App Intents. The App Intent functions as expected, and is able to change the page based on the user selection within Shortcuts (or prompted if using the App Shortcut). What I'd like to do is allow the user to be able to say "Siri, open with ."
So far, The closest I've come to understanding how this works is through the .intentsdefinition file you can create (and SiriKit in general), however the part that really confused me there is a button in the File Editor that says "Convert to App Intent." To me, this means that I should be able to use the app intent I've already authored and hook that into Siri, rather than making an entirely new function/code-block that does exactly the same thing. Ideally, that's what I want to do.
What's the right way to define this behavior?
p.s. If I had to pick an intent schema in the context of AssistantSchemas, I'd say it's closest to the "Open File" one, if that helps. I'd ultimately like to make the "pages" user-customizable so in the long run, that would be what I'd do.
I currently create a AppIntent that contains a custom AppEntity, it shows like this
struct GetTimerIntent: AppIntent {
static let title: LocalizedStringResource = "Get Timer"
@Parameter(title: "Timer")
var timer: TimerEntity
func perform() async throws -> some IntentResult {
.result(value: timerText(timer.entity))
}
static var parameterSummary: some ParameterSummary {
Summary("Get time of \(\.$timer)")
}
func timerText(_ timer: ETimer) -> String {
// Implementation Folded
}
}
struct TimerEntity: AppEntity {
var entity: ETimer
static let defaultQuery: TimerQuery = .init()
static var typeDisplayRepresentation: TypeDisplayRepresentation {
TypeDisplayRepresentation(name: "Timer")
}
var id: UUID {
entity.identifier
}
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: "\(entity.title)")
}
}
To get the timers, I create a TimerQuery type to fetch them from SwiftData containers.
struct TimerQuery: EntityQuery, Sendable {
func entities(for identifiers: [UUID]) async throws -> [TimerEntity] {
print(identifiers)
let context = ModelContext(ModelMigration.sharedContainer)
let descriptor = FetchDescriptor<ETimer>(
predicate: #Predicate {
identifiers.contains($0.identifier)
},
sortBy: [.init(\.index)]
)
let timers = try context.fetch(descriptor)
print(timers.map(\.title))
return timers.map {
TimerEntity(entity: $0)
}
}
}
Everything looks make sense since I code it. When I'm testing, the console jump
No ConnectionContext found for 105553169752832 and I can't get my datas.
How can I solve this issue?
I have an image based app with albums, except in my app, albums are known as galleries.
When I tried to conform my existing OpenGalleryIntent with @AssistantIntent(schema: .photos.openAlbum), I had to change my existing gallery parameter to be called target in order to fit the predefined shape of this domain.
Previously, my intent was configured to display as “Open Gallery” with the description “Opens the selected Gallery” in the Shortcuts app. After conforming to the photos domain, it displays as “Open Album” with a description “Opens the Provided Album”.
Shortcuts is ignoring my configured title and description now. My code builds, but with the following build warnings:
Parameter argument title of a required Assistant schema intent parameter target should not be overridden
Implementation of the property title of an AppIntent conforming to AssistantSchemaIntent should not be overridden
Implementation of the property description of an AppIntent conforming to AssistantSchemaIntent should not be overridden
Is my only option to change the concept of a Gallery inside of my app into an Album? I don't want to do this... Conceptually, my app aligns well with this domain does, but I didn't consider that conforming to the shape of an AI schema intent would also dictate exactly how it's presented to the user.
FB16283840
Hi,
I'm building an aftermarket solution to enable Apple Maps to support EV routing for any EV.
I am going through the documentation and found some gaps - does anyone know how the following properties work?
INGetCarPowerLevelStatusIntentResponse - consumptionFormulaArguments
INGetCarPowerLevelStatusIntentResponse - chargingFormulaArguments
Is there a working example that anyone has seen?
Many thanks