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

Updates to data from App Intent don't trigger view refresh in app
Hi all, I'm working on a really basic counter app as a way to explore SwiftData and have come across some behavior that I don't understand. I have a very simple App Intent that increments a user-specified counter in my app. The intent doesn't throw any errors and correctly updates the CoreData store but, when I switch back to my app from the Shortcuts app (where I'm testing the app intent), the view hasn't updated. Closing and re-opening the app shows the incremented counter value but I'd like to know if it's possible to have my app's UI update when the CoreData store is updated from outside the app without relaunching the whole app. For some brief context, here's my view and the App Intent: struct ContentView: View { @Environment(\.modelContext) private var modelContext @Query private var counters: [Counter] // ... var body: some View { NavigationStack { List { ForEach(counters) { counter in CounterRowItem(counter: counter) } .onDelete(perform: deleteItems) } // ... } } struct IncrementCounterIntent: AppIntent { static var title: LocalizedStringResource = "Increment Counter" @Parameter(title: "Name", optionsProvider: CounterOptionsProvider()) var name: String func perform() async throws -> some IntentResult & ReturnsValue<Int> { let provider = try CounterProvider() guard let counter = try provider.fetchCounters().first(where: { $0.name == name }) else { print("Couldn't find counter with name '\(name)'") return .result(value: 0) } counter.count += 1 try provider.context.save() return .result(value: counter.count) } private final class CounterOptionsProvider: DynamicOptionsProvider { func results() async throws -> [String] { try CounterProvider().fetchCounters().map { $0.name } } } }
7
5
1.3k
Sep ’23
Interactive Widget: unable to reload timeline from AppIntent
My app features two kinds of widgets, let's call them kind A and kind B. I have both A and B widgets on my Home Screen. When I tap the button on widget A (associated with App Intent), I expect widget B to also reload. However, if you call WidgetCenter.shared.reloadAllTimelines() inside the perform() method of the AppIntent, the timeline of widget B does not reload immediately. This issue only occurs on a physical device and is not consistently reproducible. On a simulator, however, widget B reloads as expected. FB13152293
3
3
682
Sep ’23
iOS 17 AppIntent and requesting confirmation for widgets
I have a home widget with buttons (new in iOS 17). In order to prevent taking action if the user taps on the widget buttons accidentally, I want to ask the user for confirmation. It appeared that requestConfirmation be exactly what I needed, but no confirmation view shows up when I invoke this method in the perform function. I have tried the following: try await requestConfirmation(result: .result(dialog: "Are you sure you want to do this?") { Image(.mdlsWhite) }) and this alternative: let confirmed: Bool = try await $name.requestConfirmation(for: self.name, dialog: IntentDialog(stringLiteral: msg)) Neither option work. I am starting to think that the requestConfirmation is not to be used with Home Widgets. Is there a better way to handle confirmations for buttons included in a Home Widget?
3
1
966
Sep ’23
Information on AudioPlaybackIntent
Is there any information on what the AudioPlaybackIntent does? The documentation doesn't give any information on it: https://developer.apple.com/documentation/appintents/audioplaybackintent I have an audio app and I want to add a play/pause button to our widget for iOS17, I'm assuming I need to use an AudioPlaybackIntent but there is no documentation on what it does. Thanks.
0
0
553
Sep ’23
Shared AVAudioPlayer State Between App and Widget: How does Apple Music Do It?
Hello Everyone, I'm working on creating an audio playback widget for my app, aiming for functionality similar to the Apple Music widget. Specifically, I've implemented a play button in my widget that triggers an AudioPlaybackIntent. This intent then interacts with a singleton class that manages my AVAudioPlayer. The issue I'm facing is that the AVAudioPlayer instance in my main app and the instance in my widget extension don't seem to share the same state. I've noticed that the Apple Music widget is capable of showing real-time changes (eg. stopping music from command center, stops it on widget UI), which implies that it has some way of sharing the playback state between the main app and the widget. How can I achieve shared state between the main app and widget for my AVAudioPlayer instance? Is there a specific approach or API that Apple Music uses to make this happen?
3
3
535
Sep ’23
Tinting the SF Symbol of an AppEntity
As you can see in the following screenshot the „Water“ selection is an AppEnum which gets a nicely tinted SF Symbol. On the other hand, the „My Home“ is an AppEntity which also uses an SF Symbol, but doesn’t get the blue tint. Why? Now my question is, how can I force the tint on the AppEntity as well? I’ve defined it the following way: var displayRepresentation: DisplayRepresentation { DisplayRepresentation( title: "\(title)", image: .init(systemName: "house", isTemplate: true) ) } But even adding the isTemplate doesn’t work here …
0
0
516
Sep ’23
How to use ParameterSummaryBuilder?
I'm trying to put together an app intent that allows a user to navigate to a specific part of my app. I've built a basic intent, and set up an AppEnum with a case for each "screen" in my app a user should be allowed to navigate to (e.g. "All Posts", "Favourite Posts", etc.). In addition, I'd like to include additional parameters based on the enum selected. For example, I'd like to include an enum case "Post" where a user can configure a specific post to navigate to. This would mean I can have an enum of "All Posts", "Specific Post", "Favourite Posts" etc. which is cleaner than having a separate intent for "Open Specific Post"... Is this possible? I can see ParameterSummaryBuilder, AppIntent.Switch etc. but there are no docs or examples using these. Can you provide more information on whether this is possible, and show an example of Swift code to do this. Thanks!
1
0
767
Sep ’23
Muting Audio in Interactive Widgets with AudioPlaybackIntent When Device is in Silent Mode
I'm encountering an intriguing issue with interactive widgets and the AudioPlaybackIntent on my device. Specifically, my problem arises when the device is set to silent mode. Despite the silence setting, selecting the category .playback continues to play sounds, which is the expected behaviour. However, when I opt for alternative categories like .ambient or .soloAmbient, these widgets cease to produce sound, even when the device is in ringer mode. I would appreciate any insights, solutions, or discussion on this matter within the Apple forum community. // This code snippet allows audio to play in widgets with interactive buttons, even in silent mode. try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) try? AVAudioSession.sharedInstance().setActive(true) // Conversely, this code snippet prevents audio playback in widgets with interactive buttons, even in silent mode. try? AVAudioSession.sharedInstance().setCategory(.ambient, mode: .default, options: []) try? AVAudioSession.sharedInstance().setActive(true) Works as expected on the Simulator, but encounters issues when tested on a physical device using Xcode 15 Beta 8
0
0
697
Sep ’23
What is Navigator in wwdc22 in Dive into App Intents.
I try to make app intent but i'm beginner at swift. so I watched wwdc vedio : Dive into App Intents. - https://developer.apple.com/videos/play/wwdc2022/10032 But i don't know what does 'Navigator' means at the code. Navigator used together with shared, than navigator is used ad singleton? Does anyone have whole sample code along with thins video? struct OpenCurrentlyReading: AppIntent { static var title: LocalizedStringResource = "Open Currently Reading" @MainActor func perform() async throws -> some IntentResult { Navigator.shared.openShelf(.currentlyReading) return .result() } static var openAppWhenRun: Bool = true }
1
0
787
Aug ’23
Migration to AppIntents doesn't work for dynamic options provider type.
We are using Intent for app shortcuts which allows user to select name from array of string. In the intent, there is only one parameter name. After migrating to app intent, it does not preserve the name of existing shortcut and every time it asks for the name. For example, I have an existing app shortcuts with name "Book 1". After migrating to AppIntent, if I run same shortcut, it ask for the name again. We are passing same books array in DynamicOptionsProvider and provideNameOptionsCollection method.. Here is the code: @available(iOS 16.0, *) struct CreateBook: AppIntent, CustomIntentMigratedAppIntent, PredictableIntent { static let intentClassName = "BookIntent" // Intent name: Book static var title: LocalizedStringResource = "Book" static var description = IntentDescription("Book") @Parameter(title: "Name", optionsProvider: BookNamesOptionsProvider()) var name: String? private struct BookNamesOptionsProvider: DynamicOptionsProvider { func results() async throws -> [String] { ["Book 1", "Book 2"] } } static var parameterSummary: some ParameterSummary { Summary("Create \(\.$name)") } static var predictionConfiguration: some IntentPredictionConfiguration { IntentPrediction(parameters: (\.$name)) { name in DisplayRepresentation( title: "Create \(name!)", subtitle: "Create Book" ) } } func perform() async throws -> some IntentResult { ... } }
0
0
425
Aug ’23
AppIntent timing out after around 25s. Are there solutions or alternatives?
I am launching an app intent from a widget button tap, which, in turn, executes a task in the background that can take up to 40 seconds. This task fails to execute completely most times, as the time out period is around 25 to 30 seconds. Is there any way to work around the app intent time limit? User feedback is not important, as this interacts with an external physical device, so the user knows the state from looking at said device. I was considering other alternatives for when the task fails to execute completely, like prompting the user to continue the task, but this doesn't seem like a valid solution, as there is no way to do this foreground interfacing from a widget. I am completely stumped with this. This was a problem with the old Intents, and it seems like it's still a problem with the new App Intents. I wish Apple would allow developers to control how much the intent would take to timeout.
0
1
483
Aug ’23
EnumerableEntityQuery references AppEntity type in the singular form when it should be plural
I’m implementing App Shortcuts in my iOS app to allow you to add and find plants. In attempt to get a “Find Plants” shortcut, I created a query that conforms to EnumerableEntityQuery and set that as the defaultQuery in my PlantAppEntity. I have the typeDisplayRepresentation set to TypeDisplayRepresentation(name: "Plant", numericFormat: "\(placeholder: .int) plants"). I added a Localizable.stringsdict to the app target, added Plant and %lld plants as the header comments shows, then clicked Localize so now English is selected in the Localization section. But when I run the app then open Shortcuts and tap my app, there’s a Find Plant shortcut, but I expected it to be titled Find Plants. When I tap the info button it shows “plant” instead of “plants” in every parameter description. When you add that action to a shortcut the placeholder is All Plant, unlike similar shortcuts from Reminders and Contacts that say “All Reminders” and “All Contacts”. The action is working properly as it returns an array of plants, the only issue is it’s using the singular form of plant in places it should be plural. Have I done something wrong, am I missing anything, or is this a bug? (FB12908309)
1
0
706
Aug ’23
AppShortcuts.strings ${applicationName} should not be mandatory on the localizable key : Invalid Utterance. Every App Shortcut utterance should have one '${applicationName}' in it.
Xcode 15 beta 6 : Xcode is looking for "${applicationName}" in the strings file keys instead of the value only. (it was working on Xcode 14) error : Invalid Utterance. Every App Shortcut utterance should have one '${applicationName}' in it.
3
1
609
Aug ’23
SuccessfulExit not working
I have made a very simple programme that checks the minutes in golang and converted it to an app. When the minutes are even it exits with code of 0 and when odd code of 1. I have made a plist that I want it to keep alive when the code is 1. The plist is provided: The programme is not being kept alive with SuccesfulExit false or array intiger 0. Is this a common problem, chip issue or system?? (I have the M1 chip and venturaOS 13) Thank you for any help you can provide
0
0
232
Aug ’23