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
Sort by:

Post

Replies

Boosts

Views

Activity

Conforming an existing AppIntent to the photos domain schema
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
2
1
521
Jan ’25
Documentation of parameters to enable Apple Maps EV routing
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
1
0
324
Jan ’25
AssistantIntent system.search behaviour
Given that iOS 18.2 is out and following documentation and WWDC example (limited to iOS 18.2+), I am attempting to use @AssistantIntent(schema: .system.search) along an AppIntent. Questions: Has anyone made this to work on a real device?! In my case (code below): when I run the intent from Shortcuts or Siri, it does NOT open the App but only calls the perform method (and the App is not foregrounded) -- changing openAppWhenRun has no effect! Strangely: If my App was backgrounded before invocation and I foreground it after, it has navigated to Search but just not foregrounded the App! Am I doing anything wrong? (adding @Parameter etc doesn't change anything). Where is the intelligence here? The criteria parameter can NOT be used in the Siri phrase -- build error if you try that since only AppEntity/AppEnum is permitted as variable in Siri phrase but not a StringSearchCriteria. Said otherwise: What's the gain in using @AssistantIntent(schema: .system.search) vs a regular AppIntent in this case?! Some code: @available(iOS 18.2, *) @AssistantIntent(schema: .system.search) struct MySearchIntent: ShowInAppSearchResultsIntent { static let searchScopes: [StringSearchScope] = [.general] static let openAppWhenRun = true var criteria: StringSearchCriteria @MainActor func perform() async throws -> some IntentResult { NavigationHandler().to(.search(.init(query: criteria.term)), from: .siri) return .result() } } Along with this ShortCut in AppShortcutsProvider: AppShortcut( intent: MySearchIntent(), phrases: [ "Search \(.applicationName)" ], shortTitle: "Search", systemImageName: "magnifyingglass" )
0
0
329
Jan ’25
Triggering a Live Activity from a Widget-Based App Intent
Hello everyone, I have an app leveraging SwiftData, App Intents, Interactive Widgets, and a Control Center Widget. I recently added Live Activity support, and I’m using an App Intent to trigger the activity whenever the model changes. When the App Intent is called from within the app, the Live Activity is created successfully and appears on both the Lock Screen and in the Dynamic Island. However, if the same App Intent is invoked from a widget, the model is updated as expected, but no Live Activity is started. Here’s the relevant code snippet where I call the Live Activity: ` await LiveActivityManager.shared.newSessionActivity(session: session) And here’s how my attribute is defined: struct ContentState: Codable, Hashable { var session: Session } } Is there any known limitation or workaround for triggering a Live Activity when the App Intent is initiated from a widget? Any guidance or best practices would be greatly appreciated. Thank you! David
1
0
386
Jan ’25
get location in app intent for interactive widgets
I have an app intent for interactive widgets. when I touch the toggle, the app intent perform to request location. func perform() async throws -> some IntentResult { var mark: LocationService.Placemark? do { mark = try await AsyncLocationServive.shared.requestLocation() print("[Widget] ConnectHandleIntent: \(mark)") } catch { WidgetHandler.shared.error = .locationUnauthorized print("[Widget] ConnectHandleIntent: \(WidgetHandler.shared.error!)") } return .result() } @available(iOSApplicationExtension 13.0, *) @available(iOS 13.0, *) final class AsyncLocationServive: NSObject, CLLocationManagerDelegate { static let shared = AsyncLocationServive() private let manager: CLLocationManager private let locationSubject: PassthroughSubject<Result<LocationService.Placemark, LocationService.Error>, Never> = .init() lazy var geocoder: CLGeocoder = { let geocoder = CLGeocoder() return geocoder }() @available(iOSApplicationExtension 14.0, *) @available(iOS 14.0, *) var isAuthorizedForWidgetUpdates: Bool { manager.isAuthorizedForWidgetUpdates } override init() { manager = CLLocationManager() super.init() manager.delegate = self } func requestLocation() async throws -> LocationService.Placemark { let result: Result<LocationService.Placemark, LocationService.Error> = try await withUnsafeThrowingContinuation { continuation in var cancellable: AnyCancellable? var didReceiveValue = false cancellable = locationSubject.sink( receiveCompletion: { _ in if !didReceiveValue { // subject completed without a value… continuation.resume(throwing: LocationService.Error.emptyLocations) } }, receiveValue: { value in // Make sure we only send a value once! guard !didReceiveValue else { return } didReceiveValue = true // Cancel current sink cancellable?.cancel() // We either got a location or an error continuation.resume(returning: value) } ) // Now that we monitor locationSubject, ask for the location DispatchQueue.global().async { self.manager.requestLocation() } } switch result { case .success(let location): // We got the location! return location case .failure(let failure): // We got an error :( throw failure } } // MARK: CLLocationManagerDelegate func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { defer { manager.stopUpdatingLocation() } guard let location = locations.first else { locationSubject.send(.failure(.emptyLocations)) return } debugPrint("[Location] location: \(location.coordinate)") manager.stopUpdatingLocation() if geocoder.isGeocoding { geocoder.cancelGeocode() } geocoder.reverseGeocodeLocation(location) { [weak self] marks, error in guard let mark = marks?.last else { self?.locationSubject.send(.failure(.emptyMarks)) return } debugPrint("[Location] mark: \(mark.description)") self?.locationSubject.send(.success(mark)) } } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { locationSubject.send(.failure(.errorMsg(error.localizedDescription))) } } I found it had not any response when the app intent performed. And there is a location logo tips in the top left corner of phone screen.
2
0
362
Jan ’25
AppIntents - Choosing a default Measurement<UnitMass> for body weight based on locale
Here’s a clearer and more concise version of your question: I’m creating an AppIntent to allow users to log their body weight. My intent includes a @Parameter defined as: @Parameter( title: "Weight", description: "Current Weight", defaultUnit: .pounds, supportsNegativeNumbers: false ) var weight: Measurement<UnitMass> This works but doesn’t respect the user’s Locale and its measurementSystem. When I add defaultUnitAdjustForLocale: true to the @Parameter macro, the default always switches to kilograms, regardless of the locale. How can I correctly set the default unit to match the user’s locale for the purpose of entering a users body weight?
0
0
261
Jan ’25
Inform iOS about AppShortcutsProvider
I've been following along with "App Shortcuts" development but cannot get Siri to run my Intent. The intent on its own works in Shortcuts, along with a couple others that aren't in the AppShortcutsProvder structure. I keep getting the following two errors, but cannot figure out why this is occurring with documentation or other forum posts. No ConnectionContext found for 12909953344 Attempted to fetch App Shortcuts, but couldn't find the AppShortcutsProvider. Here are the relevant snippets of code - (1) The AppIntent definition struct SetBrightnessIntent: AppIntent { static var title = LocalizedStringResource("Set Brightness") static var description = IntentDescription("Set Glass Display Brightness") @Parameter(title: "Level") var level: Int? static var parameterSummary: some ParameterSummary { Summary("Set Brightness to \(\.$level)%") } func perform() async throws -> some IntentResult { guard let level = level else { throw $level.needsValueError("Please provide a brightness value") } if level > 100 || level <= 0 { throw $level.needsValueError("Brightness must be between 1 and 100") } // do stuff with level return .result() } } (2) The AppShortcutsProvider (defined in my iOS app target, there are no other targets) struct MyAppShortcuts: AppShortcutsProvider { static var shortcutTileColor: ShortcutTileColor = .grayBlue @AppShortcutsBuilder static var appShortcuts: [AppShortcut] { AppShortcut( intent: SetBrightnessIntent(), phrases: [ "set \(.applicationName) brightness to \(\.$level)", "set \(.applicationName) brightness to \(\.$level) percent" ], shortTitle: LocalizedStringResource("Set Glass Brightness"), systemImageName: "sun.max" ) } } Does anything here look wrong? Is there some magical key that I need to specify in Info.plist to get Siri to recognize the AppShortcutsProvider? On Xcode 16.2 and iOS 18.2 (non-beta).
5
0
788
Jan ’25
Is it possible to Add Reply of Push Notification from Airpod using Voice ?
We want to do below addition to iOS Mobile App. Airpod announces Push notification = which is workking now we want to use voice command that "Reply to this" and sending Reply to that notification but it is saying it is not supported in your app. So basically we need to use feature - Listen and respond to messages with AirPods Do we need to add any integration inside app for this or it will directly worked with Siri settings ? Is it possible to do in non messaging App? Is it possible to do without syncing contacts ?
0
0
324
Dec ’24
AppIntents: Shortcuts phrases with parameters are not resolving correctly
Exploring AppIntents and Shortcuts. No matter what I try Siri won't understand parameters in an initial spoken phrase. For example, if I ask: "Start my planning for School in TestApp", Siri responds: "What's plan?", I say: "School" and Siri responds "Ok, starting Shool plan" What am I missing so it won't pick up parameters right away? Logs inside func entities(matching string: String) are only called after "What's plan?" question and me answering "School". No logs after the initial phrase Tried to use Apple's Trails example as a reference but with no luck
1
0
333
Dec ’24
Making onscreen content available to Siri not requesting my Transferable
Howdy, I'm following along with this sample: https://developer.apple.com/documentation/appintents/making-onscreen-content-available-to-siri-and-apple-intelligence I've got everything up and building. I can confirm that the userActivity modifier is associating my App Intent via EntityIdentifier but my custom Transferable representation (text) is never being called and when Siri is doing the ChatGPT handoff, it's just offering to send a screenshot which is what it does when it has no custom representation. What could I doing wrong? Where should I be looking?
3
0
649
Dec ’24
How to use a Decimal as @Property of AppEntity
I’m trying to use a Decimal as a @Property in my AppEntity, but using the following code shows me a compiler error. I’m using Xcode 16.1. The documentation notes the following: You can use the @Parameter property wrapper with common Swift and Foundation types: Primitives such as Bool, Int, Double, String, Duration, Date, Decimal, Measurement, and URL. Collections such as Array and Set. Make sure the collection’s elements are of a type that’s compatible with IntentParameter. Everything works fine for other primitives as bools, strings and integers. How do I use the Decimal though? Code struct MyEntity: AppEntity { var id: UUID @Property(title: "Amount") var amount: Decimal // … } Compiler Error This error appears at the line of the @Property definition: Generic class 'EntityProperty' requires that 'Decimal' conform to '_IntentValue'
1
0
478
Dec ’24
Basic app intent always showing error in Shortcuts app "The action could not run because an internal error occurred."
I have a very basic App Intent extension in my macOS app that does nothing than accepting two parameters, but running it in Shortcuts always produces the error "The action “Compare” could not run because an internal error occurred.". What am I doing wrong? struct CompareIntent: AppIntent { static let title = LocalizedStringResource("intent.compare.title") static let description = IntentDescription("intent.compare.description") static let openAppWhenRun = true @Parameter(title: "intent.compare.parameter.original") var original: String @Parameter(title: "intent.compare.parameter.modified") var modified: String func perform() async throws -> some IntentResult { return .result() } }
8
0
650
3w
Testing app intents and forcing Shortcuts app to refresh
The Verify the behavior of your intent in Simulator or on-device documentation says that it's sufficient to build and run the app and open the Shortcuts app to test an app intent, but that doesn't seem to be the case. I always needed to at least move the debugged app to the Applications folder before the app intents showed up in Shortcuts, and even then, most of the times I also need to wait a lot or restart the Mac. When updating an existing app intent (for instance by changing its title), building the app, overwriting the existing one in the Applications folder and restarting Shortcuts is not sufficient to make the new title appear in Shortcuts. Is there an efficient way to test app intents in the Shortcuts app? I already created FB15638502 one month ago but got no response.
0
0
305
Dec ’24
App Intent title and other localized strings not showing correctly in Shortcuts app on macOS 15
I rarely use the Shortcuts app, so it took me a while to notice that my app's app intents all show incorrectly on macOS 15. On macOS 14 and 13, they used to show correctly, but now it seems that all localized strings show the key rather than the localized value. @available(iOS 16.0, macOS 13.0, *) struct MyAppIntent: AppIntent { static let title = LocalizedStringResource("key1", comment: "") static let description = IntentDescription(LocalizedStringResource("key2", comment: "")) ... } In Localizable.xcstrings file I have defined all the strings, for instance I have associated key1 with the value Title, but while the Shortcuts app used to display Title, it now displays key1. Is this a known issue or did something change in macOS 15 that would require me to update something?
10
0
597
3w
Intents not showing up in WatchOS Shortcuts
I have developed a standalone WatchOS app which runs a stopwatch. I want to develop a shortcut that launches the stopwatch. So far I have created the Intent file, and added the basic code (shown below) but the intent doesn't show in the shortcuts app. In the build, I can see the intent metadata is extracted, so it can see it, but for some reason it doesn't show in the watch. I downloaded Apple's demo Intent app and the intents show in the watch there. The only obvious difference is that the Apple app is developed as an iOS app with a WatchOS companion, whereas mine is standalone. Can anyone point me to where I should look for an indicator of the problem? Many thanks! // // StartStopwatch.swift // LapStopWatchMaster import AppIntents import Foundation struct StartStopWatchAppIntent: AppIntent { static let title: LocalizedStringResource = "Start Stopwatch" static let description = IntentDescription("Starts the stopwatch and subsequently triggers a lap.") static let openAppWhenRun: Bool = true @MainActor func perform() async throws -> some IntentResult { // Implement your app logic here return .result(value: "Started stopwatch.") } }
3
0
418
Dec ’24
Why is applicationWillEnterForeground called on first launch when using AppIntent with openAppWhenRun = true?
Hello, I’ve implemented a feature in my app using AppIntent. When the app is not running in the background and is launched for the first time via a shortcut, both application:didFinishLaunchingWithOptions: and applicationWillEnterForeground: are called. Normally, on the first launch, applicationWillEnterForeground: is not invoked. However, this behavior seems to occur only when the app is launched through a shortcut. I’d like to understand why applicationWillEnterForeground: is being called in this scenario. For reference, the AppIntent has openAppWhenRun set to true. Thank you in advance for your help!
1
0
355
Dec ’24
Why is applicationWillEnterForeground called on first launch when using AppIntent with openAppWhenRun = true?
Hello, I’ve implemented a feature in my app using AppIntent. When the app is not running in the background and is launched for the first time via a shortcut, both application:didFinishLaunchingWithOptions: and applicationWillEnterForeground: are called. Normally, on the first launch, applicationWillEnterForeground: is not invoked. However, this behavior seems to occur only when the app is launched through a shortcut. I’d like to understand why applicationWillEnterForeground: is being called in this scenario. For reference, the AppIntent has openAppWhenRun set to true. Thank you in advance for your help!
3
0
388
Dec ’24