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

Detect when main app launched by LockedCameraCapture for permission
I have a LockedCameraCapture extension working well, however there is one situation I cannot find a solution to. If the user has not yet provided camera access permission then the main app will be launched rather than the LockedCameraCapture extension. I cannot find a mechanism by which my main app can detect that this was the reason for the launch and thereby request permission. When the button is pressed from the control center without permission the app is run and the CameraCaptureIntent is called so I can prompt the user from there. However, as best I can tell the CameraCaptureIntent is not called when launched from a locked Lock Screen, the app is simply opened. My app has a variety of functions, most of which do not involve the camera so I cannot just always prompt the user for camera access on open. Is there any mechanism by which my main app can detect it was launched for this reason so it could ask for permission? Thank you!
4
1
513
Sep ’24
Correspondent color to an AppEntity in AppIntent 1:1
Hey folks, I am creating one Widget AppIntent and I want to have as parameters X amount of scripts (let’s call them items) and each item has it’s own color associated (in this screenshot as String just to simplify). First image is the code I have now which allows the user to select several items, second image is the only way I found to allow associating one item to one color. Is there a smarter way of doing it?
0
0
247
Aug ’24
Search intent using ShowInAppSearchResultsIntent
ShowInAppSearchResultsIntent is supported from iOS 17.2. However while consuming the API without @AssistantIntent(schema: .system.search) it throws a error as shown below. I am looking for a way I can make use of ShowInAppSearchResultsIntent in iOS 17 without having to use iOS 18 APIs for @AssistantIntent(schema: .system.search). Is there any way to achieve this?
3
0
415
Aug ’24
Disable App Shortcuts without releasing a new build
I'm trying to create an App Shortcut so that users can interact with one of my app's features using Siri. I would like to be able to turn this shortcut on or off at runtime using a feature toggle. Ideally, I would be able to do something like this. struct MyShortcuts: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { // This shortcut is always available AppShortcut( intent: AlwaysAvailableIntent(), phrases: ["Show my always available intent with \(.applicationName)"], shortTitle: "Always Available Intent", systemImageName: "infinity" ) // This shortcut is only available when "myCoolFeature" is available if FeatureProvider.shared.isAvailable("myCoolFeature") { AppShortcut( intent: MyCoolFeatureIntent(), phrases: ["Show my cool feature in \(.applicationName)"], shortTitle: "My Cool Feature Intent", systemImageName: "questionmark" ) } } } However, this does not work because the existing buildOptional implementation is limited to components of type (any _AppShortcutsContentMarker & _LimitedAvailabilityAppShortcutsContentMarker)?. All other attempts at making appShortcuts dynamic have resulted in shortcuts not working at all. I've tried: Creating a makeAppShortcuts method that returns [AppShortcut] and invoking this method from within the appShortcuts Extending AppShortcutsBuilder to support a buildOptional block isn't restricted to a component type of (any _AppShortcutsContentMarker & _LimitedAvailabilityAppShortcutsContentMarker)? Extending AppShortcutsBuilder to support buildArray and using compactMap(_:) to return an empty array when the feature is disabled I haven't used SiriKit before but it appears that shortcut suggestions were set at runtime by invoking setShortcutSuggestions(_:), meaning that what I'm trying to do would be possible. I'm not against using SiriKit if I have to but my understanding is that the App Intents framework is meant to be a replacement for SiriKit, and the prompt within Xcode to replace older custom intents with App Intents indicates that that is indeed the case. Is there something obvious that I'm just missing or is this simply not possible with the App Intent framework? Is the App Intent framework not meant to replace SiriKit and should I just use that instead?
2
1
649
Aug ’24
How to Prevent App Intents from Appearing in the Shortcuts App in SwiftUI Interactive Widgets
I'm working on a SwiftUI interactive widget using AppIntent. However, I want to prevent my AppIntents from appearing in the Shortcuts app. Currently, all my AppIntents are showing up in the Shortcuts app, but I only want them to be used within my widget. Is there a way to restrict the visibility of AppIntents so they don't appear in the Shortcuts app? Here is a simplified version of my AppIntent: import AppIntents struct MyWidgetIntent: AppIntent { static var title: LocalizedStringResource = "My Widget Intent" func perform() async throws -> some IntentResult { // Intent logic here } } I've looked into the documentation but haven't found a clear way to achieve this.
1
0
494
Aug ’24
Limitations of AppIntentsExtension member intents
When considering an intent's membership in an AppIntentsExtension vs. main target or an xcframework linked to the main target (with Xcode 16), are there certain capabilities unavailable to Extension member AppIntents? (Specifically, say reuse in AppShortcutsProvider, launching deep links via openAppWhenRun, reuse in Widgets or LiveActivities?) For example, the Watch action button warns to only use intents in the main Watch target.
1
0
295
Sep ’24
Reading widget configuration intent when launching the app
I'm creating a configurable widget using AppIntentConfiguration in my SwiftUI app and wanted to read configuration's payload when the user taps on the widget and launches the app. Having read the WidgetKit's documentation I noticed I can just call userActivity.widgetConfigurationIntent(of: MyWidgetConfigurationAppIntent.self) inside .onContinueUserActivity() modifier, to get the intent's instance. This function works and returns the instance when user taps on the widget and the app is already running in the background, but returns nil when the app launches for the first time. Am I doing something wrong here, is this a desired behaviour? Is using Deep Links a more suited solution for this use case? I'm really not liking the idea of serialising instances of Measurement and UnitMass/UnitTemperature into URLs. Here's a sample code to illustrate: @main struct WidgetIntentTestApp: App { @State private var favouriteEmoji: String? private let intentActivityName = String(describing: ConfigurationAppIntent.self) var body: some Scene { WindowGroup { ContentView(favouriteEmoji: favouriteEmoji) .onContinueUserActivity(intentActivityName) { userActivity in guard let intent = userActivity.widgetConfigurationIntent(of: ConfigurationAppIntent.self) else { /// Intent is `nil` when the user activity `launches the app for the first time`. /// I would have expected this to work given the user activity's `.name` clearly matches the Intent's name fatalError("Expected intent but received `nil` - this should not have happened.") } favouriteEmoji = intent.favoriteEmoji } } } }
0
0
408
Aug ’24
AppIntent Title Localization
Does anyone know how to localize the title of the shortcut? I tried to create a localizable file and then do a french translation. However, when I reference it as my shortcut title and change my simulator's language to the translated language (in this case french) it still displays the title in the english translation. for example: my Localizable.strings file says in english: "shortcutTitle" = "Hello!"; in french: "shortcutTitle" = "Bonjour!"; and then my AppIntent says: static var title: LocalizedStringResource{return LocalizedStringResource("shortcutTitle")}
1
0
571
Jul ’24
Control Center widget won't show snippet view
Has anyone been able to create a Control Center widget that opens a snippet view? There are stock Control Center widgets that do this, but I haven't been able to get it to work. Here's what I tried: struct SnippetButton: ControlWidget { var body: some ControlWidgetConfiguration { StaticControlConfiguration( kind: "***.***.snippetWidget" ) { ControlWidgetButton(action: SnippetIntent()) { Label("Show Snippet", systemImage: "map.fill") } } .displayName(LocalizedStringResource("Show Snippet")) .description("Show a snippet.") } } struct SnippetIntent: ControlConfigurationIntent { static var title: LocalizedStringResource = "Show a snippet" static var description = IntentDescription("Show a snippet with some text.") @MainActor func perform() async throws -> some IntentResult & ProvidesDialog & ShowsSnippetView { return .result(dialog: IntentDialog("Hello!"), view: SnippetView()) } } struct SnippetView: View { var body: some View { Text("Hello!") } }
3
1
448
Jul ’24
Unable to observe Focus status changes from an Intents app extension
I am writing a communication app that relies on the INShareFocusStatusIntentHandling protocol. However, it appears this API is not functional, even with the proper permissions and entitlements. Given the example code here, I am unable to trigger the logs in the INShareFocusStatusIntentHandling extension. In this code, when enabling or disabling focus, line 33 of IntentHandler.swift never gets logged, even though FocusStatusCenter is authorized for parent app, UserNotifications authorized for parent app (target), and Communication Notifications entitlement has been added to the parent app. I am also unable to hit any breakpoints in the extension. It seems as if the extension is simply never triggered -- maybe even broken at the OS-level. I have tried both iOS 17 and the latest 18 beta. Other users have reported similar difficulties in these forums. To replicate, Install the example app. Give the app UserNotifications and FocusStatus permissions. Background the app. Change focus status. Check console. Notice that the extension handler is never triggered/logged.
1
0
493
Jul ’24
Dynamic AssistantSchema.CameraEnum
Hi, I have some questions about the new AssistantSchema.CameraEnum.captureDevice introduced with iOS 18 beta 4. Here's the context. I create a intent: @AssistantIntent(schema: .camera.setDevice) struct SetDeviceIntent { var device: CaptureDevice func perform() async throws -> some IntentResult { .result() } } @AssistantEnum(schema: .camera.captureDevice) enum CaptureDevice: String { case front case back case ultrawide } Some CaptureDevice cases are not available on some devices. e.g: CaptureMode.ultrawide is only available on iPhone, not on iPad. How can we make CaptureDevice dynamic? I don't think AppEnum supports @Dependency or something else.
0
2
402
Jul ’24
iOS 18 @AssistantIntent's marked with @available crashing on older OS's
Is anyone else seeing their apps crash on iOS/macOS 17.4/14.4 and newer when building a project that simply just includes the iOS 18 @AssistantIntent Macro? The beta 4 releases still have this problem. There are no notes about this that I have seen in the beta release notes. Crash message shown in console when trying to run on 17.4, 17.5, 17.5.1, etc: dyld[21935]: Symbol not found: _$s10AppIntents15AssistantSchemaV06IntentD0VAC0E0AAWP Referenced from: <F7A1FEF0-F3B0-379C-A914-D1FB0BA7C693> /Users/jonathan/Library/Developer/CoreSimulator/Devices/CA308F47-BCA8-4429-8599-1BB1CCEAB5B6/data/Containers/Bundle/Application/D7DC8E16-90DB-406A-A521-20F18326E4A7/IntentDemo.app/IntentDemo.debug.dylib Expected in: <88E18E38-24EC-364E-94A1-E7922AD247AF> /Library/Developer/CoreSimulator/Volumes/iOS_21F79/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.5.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/AppIntents.framework/AppIntents Obviously, the new Apple Intelligence AssistantIntents only work on the 2024 OS releases. However, even when these new App Intents are marked with @available(iOS 18, macOS 15, *), the app crashes on any earlier OS version. But it runs just fine on iOS 18 and macOS 15... I would love for me to just have done something wrong but I don’t think I have… Here is the sample project: https://github.com/JTostitos/FB14323923 Maybe it's a compiler issue thats failing to strip out the macro when building for older OS's or an Xcode issue - I have no idea. I just would like to know why its not working and how to resolve it. Thanks in advance for anyones help...
4
3
819
3w
Dependency between AssistantSchema.CameraEnum
Hi, I have some questions about the new AssistantSchema.CameraEnum.captureMode and AssistantSchema.CameraEnum.captureDevice introduced with iOS 18 beta 4. Here's the context. I create a intent: @AssistantIntent(schema: .camera.startCapture) struct StartCaptureIntent { var captureMode: CaptureMode var timerDuration: CaptureDuration? var device: CaptureDevice? func perform() async throws -> some IntentResult { .result() } } And these app enums: @AssistantEnum(schema: .camera.captureDevice) enum CaptureDevice: String { case front case back case ultrawide } @AssistantEnum(schema: .camera.captureMode) enum CaptureMode: String { case modeA case modeB } Some CaptureDevice cases are not available in some CaptureMode. e.g: CaptureMode.modeA only supports CaptureDevice.back and CaptureDevice.front. In a classic AppIntent, I would create an AppEntity to represent CaptureDevice and use @IntentParameterDependency<CapturePhotoIntent>( \.$captureMode) to create a dependency between the captureMode and the captureDevice parameters. How can we create this dependency between two @AssistantEnum? I'm not sure this is possible as @AssistantEnum creates AppEnum.
0
1
362
Jul ’24
AssistantIntent for Photos without library access
The new .photos AssistantSchema for intents allow integrating App Intents for Photos-related actions with Apple Intelligence. I was wondering if it would be possible to create intents that do not require full library access. Our app supports loading image from Photos via the PHPicker, which doesn't require any user permission. Now we want to support the .photos.openAsset schema in an app intent to allow interactions like "Open this image in BeCasso and apply preset X". Would that be possible without full library access?
0
0
413
Jul ’24
Interactive Live Activity Bug in iOS 18 - perform not called
In iOS 18 (beta 1-4) when you set openAppWhenRun = false in your AppIntent of your live activity the perform function never gets called. In iOS 16 and 17 my live activities work. I have downloaded other apps and in their live activities any button tab which doesn´t open the app is also doing nothing in iOS 18. Has anyone got this working? Any comments from an Apple engineer on this?
3
1
644
Aug ’24
Control Center Widget: Unable to read configuration from ControlConfigurationIntent in SetValueIntent
I've created a control centre widget modelled on the talk in "Extend your app's controls across the system". In the talk, the user can select which timer they want to start ("work" or "violin"). The specific timer is passed to ToggleTimerIntent as follows: ControlWidgetToggle( timerState.timer.name, isOn: timerState.isRunning action: ToggleTimerIntent(timer: timerState.timer) ) { isOn in ... } However, I can't find a way to access the timer value from inside my ToggleTimerIntent, since this code isn't provided in the talk. An AppIntent must provide an empty init(), so I've specified timer as an option String: @available(iOS 18, *) struct ToggleTimerIntent: SetValueIntent { static let title: LocalizedStringResource = "Toggle Timer" // This value isn't never populated. var timer: String? @Parameter(title: "Running") var value: Bool func perform() async throws -> some IntentResult { if let timer { } else { // Always here } } } When I backtrace the code, ToggleTimerIntent is instantiated several times, however perform() is only called on an instance where the timer value isn't provided.
1
0
488
Jul ’24
Disable AppIntent for iPadOS
My application is being supported by both iOS and iPadOS platforms. I would like to add AppIntents only on iOS and not on iPadOS. I have not found any blogs related to it. Is it possible? If so, May I know how can we do it? If not, what is the best practice to avoid showing Siri shortcuts on iPad.
1
0
463
Jul ’24
How to extend my exist Toggle with intents
I create a toggle component based on Toggle public struct Checkbox: View { ... public init(...) { ... } public var body: some View { return HStack(spacing: 8) { ZStack { Toggle("", isOn: $isPrivateOn) ... } ... } } } how can I create a init method to support init with AppIntent like: // Available when SwiftUI is imported with AppIntents @available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) extension Toggle { /// Creates a toggle performing an `AppIntent`. /// /// - Parameters: /// - isOn: Whether the toggle is on or off. /// - intent: The `AppIntent` to be performed. /// - label: A view that describes the purpose of the toggle. public init<I>(isOn: Bool, intent: I, @ViewBuilder label: () -> Label) where I : AppIntent }
1
0
426
Jul ’24