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

177 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Siri not recognizing the parameter in the phrase
I am trying to create an "OpenShowIntent" that allows the user to open a show from outside the app by either invoking the shortcut and provide a showName and/or by asking Siri "Open (.$showName) in (.applicationName)". Currently the shortcut works and but Siri doesn't recognize the showName and keeps on loading when I say the phrase with a show name. I was wondering where I am going wrong. Here are some of the code below: OpenShowIntent.swift: import Foundation import AppIntents import Models @available(iOS 16.0, *) struct OpenShowIntent: AppIntent { static var title: LocalizedStringResource = "Open a Show" static var openAppWhenRun = true @Parameter(title: "Show", optionsProvider: ShowEntityQuery()) var show: ShowEntity? @Parameter(title: "Show Name") var showName: String static var parameterSummary: some ParameterSummary { Summary("Open \(\.$showName) in (APP NAME)") } @MainActor func perform() async throws -> some IntentResult & ProvidesDialog { var showToOpen: ShowEntity if let show = show { showToOpen = show } else { let params = ElasticSearchParams(query: showName) let searchResults = try await IntentsHelper.getShows(searchParams: params) let entities = searchResults.map { show in ShowEntity(id: show.id, name: show.displayName, posterUrl: show.posterImageUrl) } showToOpen = try await $show.requestDisambiguation( among: entities, dialog: "Choose a show from this list?" ) } let deepLink = DeepLink( type: .show( showId: showToOpen.id, showDateStr: nil, voucher: nil, reviewModalParams: nil ) ) let url = try deepLink.createURL(source: nil) IntentsHelper.openLink(url: url) return .result(dialog: "Show '\(showToOpen.name)' opened successfully.") } } ShowEntity.swift: import Foundation import AppIntents import Models @available(iOS 16.0, *) struct ShowEntity: AppEntity { typealias DefaultQuery = ShowEntityQuery var id: Int var name: String var posterUrl: URL? static var typeDisplayRepresentation: TypeDisplayRepresentation = "Show" var displayRepresentation: DisplayRepresentation { var image: DisplayRepresentation.Image? if let imageUrl = posterUrl { image = DisplayRepresentation.Image(url: imageUrl) } return DisplayRepresentation( title: LocalizedStringResource(stringLiteral: name), subtitle: nil, image: image ) } static var defaultQuery = ShowEntityQuery() init(id: Int, name: String, posterUrl: URL?) { self.id = id self.name = name self.posterUrl = posterUrl } } ShowEntityQuery.swift: import Foundation import AppIntents import Models @available(iOS 16.0, *) struct ShowEntityQuery: EntityStringQuery { func entities(for identifiers: [Int]) async throws -> [ShowEntity] { let params = ElasticSearchParams(showIds: identifiers) let searchResult = try await IntentsHelper.getShows(searchParams: params) return searchResult.map { show in ShowEntity(id: show.id, name: show.displayName, posterUrl: show.posterImageUrl) } } func suggestedEntities() async throws -> [ShowEntity] { let params = ElasticSearchParams( showIds: BookmarksManager.sharedManager.getBookmarkShowIdsAsArray() ) let searchResult = try await IntentsHelper.getShows(searchParams: params) return searchResult.map { show in ShowEntity(id: show.id, name: show.displayName, posterUrl: show.posterImageUrl) } } func entities(matching query: String) async throws -> [ShowEntity] { let params = ElasticSearchParams(query: query) print("entities(matching:) called with query: \(query)") let searchResult = try await IntentsHelper.getShows(searchParams: params) return searchResult.map { show in ShowEntity(id: show.id, name: show.displayName, posterUrl: show.posterImageUrl) } } } ShortcutsProvider.swift: import Foundation import AppIntents @available(iOS 16.0, *) struct TTShortcuts: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { return [ AppShortcut( intent: OpenShowIntent(), phrases: [ "View show in \(.applicationName)", "Open \(\.$showName) in \(.applicationName)", "Show \(\.$showName) in \(.applicationName)", "Find \(\.$showName) in \(.applicationName)", "Search for \(\.$showName) in \(.applicationName)" ], shortTitle: "Open show", systemImageName: "pencil.circle" ) ] } static var shortcutTileColor: ShortcutTileColor = .blue }
0
0
111
3d
ControlConfigurationIntent won't open the app despite setting openAppWhenRun = true
I am working on building Control widgets for our app and have noticed that openAppWhenRun doesn't seem to work for any ControlConfigurationIntent. When attaching the debugger to the widget extension in a sample project, I see the following error: Unknown NSError The operation couldn’t be completed. (LNActionExecutorErrorDomain error 2018.) This is reproducible as of Xcode 16.0 Beta 2 and Beta 3. I have noted that using an OpenIntent, with a parameter called target that conforms to AppEnum seems to open the app properly, but if I use that workaround, adding any additional parameters to the OpenIntent seems to break things again. Are others seeing this issue? I have feedback FB14357691. Here's some sample code below to reproduce: var body: some ControlWidgetConfiguration { AppIntentControlConfiguration(kind: "Open Any Screen", intent: OpenAppScreenIntent.self) { template in ControlWidgetButton(action: template) { Label { Text("Open App") } icon: { Image(systemName: "calendar") } }.tint(.red) } } } enum AppScreen: CaseIterable { case calendar case campus case search var title: String { switch self { case .calendar: "Calendar" case .campus: "Campus" case .search: "Search" } } } struct OpenAppScreenIntent: ControlConfigurationIntent { static var title: LocalizedStringResource = "Open app to a screen" static var description = IntentDescription("Opens the app.") /// The app should open regardless of what happens here static let openAppWhenRun: Bool = true @Parameter(title: "Screen", optionsProvider: OsuScreenOptionsProvider()) var screen: String? struct OsuScreenOptionsProvider: DynamicOptionsProvider { func results() async throws -> ItemCollection<String> { var screenTitles: [String] = [] for screen in AppScreen.allCases { async let title = screen.title await screenTitles.append(title) } return ItemCollection { ItemSection(items: screenTitles.map { IntentItem($0)}) } } func defaultResult() async -> String? { return "Campus" } } @MainActor func perform() async throws -> some IntentResult { #warning("The app should open regardless of what happens in this method, but it doesn't") return .result() } }
5
0
124
3d
"Unknown extension process" is displayed after app updating
Hello. In iOS 17, after updating the app, when trying to "Edit Widget" from a long press on the widget, "Unknown extension process" is displayed and the widget cannot be edited. At this time, the widget becomes completely white (or completely black), and it cannot be fixed without restarting the iPhone. This issue occurs sporadically on some devices. The implementation uses AppIntentTimelineProvider. Does anyone know a solution, workaround, or the cause of this problem? Thank you.
0
0
101
5d
Chaining app intents in code
I would like to split up my intents into smaller intents with more atomic pieces of functionality that I can then call one intent from another. For example: struct SumValuesIntent: AppIntent { static var title: LocalizedStringResource { "Sum Values" } let a: Int let b: Int init(a: Int, b: Int) { self.a = a self.b = b } init() { self.init(a: 0, b: 0) } func perform() async throws -> some IntentResult { let sum = a + b print("SumValuesIntent:", sum) return .result(value: sum) } } struct PrintValueIntent: AppIntent { static var title: LocalizedStringResource { "Print Value" } let string: String init(string: String) { self.string = string } init() { self.init(string: "") } func perform() async throws -> some IntentResult { print("PrintValueIntent:", string) return .result() } } What is the best way to chain intents like these? I tried .result(opensIntent: PrintValueIntent(string: String(describing: sum))) as the return type of SumValuesIntent.perform but that doesn't seem to work. Then I tried try await PrintValueIntent(string: String(describing: sum)).perform() as the return type and that works but I'm not sure that's the correct way to do it.
0
0
158
1w
EntityPropertyQuery with property from related entity
Hi, I am working on creating a EntityPropertyQuery for my App entity. I want the user to be able to use Shortcuts to search by a property in a related entity, but I'm struggling with how the syntax for that looks. I know the documentation for 'EntityPropertyQuery' suggests that this should be possible with a different initializer for the 'QueryProperty' that takes in a 'entityProvider' but I can't figure out how it works. For e.g. my CJPersonAppEntity has 'emails', which is of type CJEmailAppEntity, which has a property 'emailAddress'. I want the user to be able to find the 'person' by looking up an email address. When I try to provide this as a Property to filter by, inside CJPersonAppEntityQuery, but I get a syntax error: static var properties = QueryProperties { Property(\CJPersonEmailAppEntity.$emailAddress, entityProvider: { person in person.emails // error }) { EqualToComparator { NSPredicate(format: "emailAddress == %@", $0) } ContainsComparator { NSPredicate(format: "emailAddress CONTAINS %@", $0) } } } The error says "Cannot convert value of type '[CJPersonEmailAppEntity]' to closure result type 'CJPersonEmailAppEntity'" So it's not expecting an array, but an individual email item. But how do I provide that without running the predicate query that's specified in the closure? So I tried something like this , just returning something without worrying about correctness: Property(\CJPersonEmailAppEntity.$emailAddress, entityProvider: { person in person.emails.first ?? CJPersonEmailAppEntity() // satisfy compiler }) { EqualToComparator { NSPredicate(format: "emailAddress == %@", $0) } ContainsComparator { NSPredicate(format: "emailAddress CONTAINS %@", $0) } } and it built the app, but failed on another the step 'Extracting app intents metadata': error: Entity CJPersonAppEntity does not contain a property named emailAddress. Ensure that the property is wrapped with an @Property property wrapper So I'm not sure what the correct syntax for handling this case is, and I can't find any other examples of how it's done. Would love some feedback for this.
0
0
182
1w
muting SIRI via AppIntents
We're using App Intents to launch are control our app via Siri. Siri's responses have been fairly random, some with a "Done" popup, others with a verbal confirmation, others saying "I'm sorry, there's been a problem". The latter is bogus and doesn't look good to potential investors when the app is actually working fine. There appears to be no way in code that I've been able to find so far that would have been tell Siri to STFU. Let us handle our own errors. Otherwise is there a means to supply Siri with a dictionary of restored messages that could be triggered inside the app?
1
0
193
2d
Shortcut Execution Speed?
Is there anything that can be done to speed up the execution of a Shortcut? There is a Shortcut that many users opt to use with my app that is only effective if it runs immediately - the reality, though, is that it often takes 1-2 seconds for the Shortcut to trigger, rendering it largely useless (the Shortcut is meant to prevent users from being able to disable Screen Time in Settings). Has anyone had success with this, and/or are there other approaches we could be taking?
0
0
125
1w
DisplayRepresentation.Image and custom SF Symbol
Hi, I have a AppEnum and I try to use a custom SF Symbol as DisplayRepresentation.Image but it's not working. I get a blank image when AppEnum picker appears. The custom SF Symbol is stored in the target's asset catalog and it works in the target (eg: Image(named: "custom_sfsymbol"). The issue occurs when I try to use it in a DisplayRepresentation static var caseDisplayRepresentations: [Self: DisplayRepresentation] = [ .sample : DisplayRepresentation(title: "sample_title", image: DisplayRepresentation.Image(named: "custom_sfsymbol")), Can we use a custom SF Symbol in a DisplayRepresentation.Image?
1
0
143
2d
AppIntents don't show up in Shortcuts app when in SPM package
Hi there, I successfully created an AppIntent for our app, and when I had it in the same target as our main app it showed up fine in the shortcuts app. Then I realized that many of the new System Control widgets introduced in iOS 18 (e.g. lockscreen, control center) live in the widget extension target, but they also need to reference that same AppIntent. So to fix this, I thought I'd migrate out the code into it's own SPM package that both the WidgetExtension and the Main App processes can reference. However, after doing that and rebuilding, the intent no longer shows up in the Shortcuts app. Furthermore, my AppShortcutsProvider class now has this error when trying to define the list of appShortcuts: App Intent <name> should be in the same target as AppShortcutsProvider Is this intended, and if so, how do we reference the same AppIntent across multiple targets?
1
0
135
6d
App Intents "Text" parameters seem broken in iOS 17.6 beta
I'm getting widespread reports from users trialling iOS 17.6 public beta that Siri Shortcuts are failing whenever they enter any text that looks like a URL. It's getting reported to me because my app happens to have an app intent with a string parameter which can contain a URL in some circumstances. However it's easily reproducible outside of my app: just create a 2 line shortcut like the one below. If you change "This is some text" to "https://www.apple.com" the shortcut below will fail: In iOS 17.5 entering "https://www.apple.com" works fine. I've raised feedback on this (FB14206088) but can anyone confirm that this is indeed a bug and not some weird new feature of Shortcuts where the contents of a variable can somehow change the type of a variable? It would be very, very bad if this were so.
1
0
239
1w
iOS18, interactive widget not respond (AppIntent not working)
here is my case: i add the AppIntent to both your app and widget extension targets. the intent will run my app process when app is running. it works perfectly on iOS 17. but iOS 18, my app process never called. i download app's demo, https://developer.apple.com/documentation/widgetkit/emoji-rangers-supporting-live-activities-interactivity-and-animations it looks like the same issue. it runs well because even it runs in the widget extension target, it still can present expected UI. but in real case, we need to run the app process to do some work. by debugging, i found the app process never called(set breakpoint). i add openAppWhenRun, it works well on iOS 18. but it will open the app when the widget is running. it is not what i want.
1
1
256
1w
openAppWhenRun makes AppIntent crash when launched from Control Center.
Adding the openAppWhenRun property to an AppIntent for a ControlWidgetButton causes the following error when the control is tapped in Control Center: Unknown NSError The operation couldn’t be completed. (LNActionExecutorErrorDomain error 2018.) Here’s the full ControlWidget and AppIntent code that causes the errorerror: Should controls be able to open apps after the AppIntent runs, or is this a bug?
3
1
346
1w
Framework compilation with Command CodeSign failed with a nonzero exit code
I am trying to extract a protocol from an app to be able to use it in a siri intent. Yet when I compile it I get: note: Injecting stub binary into codeless framework (in target 'Virtual Tags Framework' from project 'Virtual Tags Framework') /Users/fabriziobartolomucci/Library/Developer/Xcode/DerivedData/Virtual_Tags_Framework-chxutmulwgujeiceazyyzaphwner/Build/Products/Debug-iphonesimulator/Virtual_Tags_Framework.framework/Frameworks/ARKit.framework/Versions/A: bundle format unrecognized, invalid, or unsuitable Command CodeSign failed with a nonzero exit code
1
0
189
1w
App Intents in frameworks
In previous years it seems there were limitations about where AppIntent types could live in your code base for them to be surfaced up to the Shortcuts app. Specifically, they needed to be in the top level app or extension target. However, WWDC24's What's new in App Intents talks about "Framework Improvements" and has a slide that implies that AppEntity, AppEnum, AND AppIntent types can live in a framework. Is this actually the case? I can see the Metadata.appintents in the build products of my framework, and my intent is included in the JSON, but these intents never make it into the Shortcuts app when I install an app that consumes the framework. I'm testing this with Xcode 16b1 in a iOS 18 simulator.
2
1
289
3w
App Intent snippet view does't able to fetch color for xcassets.
We have an existing app in which we have implemented AppShortcuts. The snippet view works fine in iOS 17 while in iOS18 beta, it doesn't able to fetch color from xcassets. If we use system colours or UIColor it's working fine. Not working Color("progressColor") Working Color(uiColor: UIColor(named: "progressColor")!) Color.red Color(hex: "3881d3") // Note: We created Color extension to generate color from hex string.
0
0
180
4w