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

178 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

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
233
Aug ’23
Incorrect Metadata.appintents with Xcode 14.3?
Recently (I think when updated to Xcode 14.3) my macOS Shortcut actions (implemented via AppIntent) started having a problem: When I click an action's AppEntity parameter I see the following error instead of seeing a list of entries to select from. The action “Demo Action” could not run because an internal error occurred. One difference that I notice between my builds that didn't exhibit this error and my builds that do exhibit the error: Working builds include objects.appintentsmanifest in the metadata folder Builds that break with the above behavior do not include that file Did something change in recent Xcode? What do I need to do so that Shortcuts app will run my queries again and provide popups so that I can select queried AppEnties? To recreate the problem I created a new Document Based App in Xcode 14.3 and included the following code. I then dragged "Demo Action" into a new Shortcut and clicked "Show More" and then clicked "Books: Choose". import AppIntents struct BookEntity: Identifiable, AppEntity { var id: UUID @Property(title: "Title") var title: String var displayRepresentation: DisplayRepresentation { DisplayRepresentation(title: LocalizedStringResource(stringLiteral: title)) } init(id: UUID, title: String?) { self.id = id self.title = title ?? "Unknown Title" } static var typeDisplayRepresentation: TypeDisplayRepresentation = "Book" static var defaultQuery = BookQuery() } struct BookQuery: EntityStringQuery { func entities(for identifiers: [UUID]) async throws -> [BookEntity] { library.filter { identifiers.contains($0.id) } } func entities(matching query: String) async throws -> [BookEntity] { library.filter { $0.title.localizedCaseInsensitiveContains(query) } } func suggestedEntities() async throws -> [BookEntity] { library } } struct DemoAction: AppIntent { static var title: LocalizedStringResource = "Demo Action" @Parameter(title: "Books") var books: [BookEntity] func perform() async throws -> some IntentResult { .result() } } let library: [BookEntity] = [ BookEntity(id: UUID(), title: "The Hobbit"), BookEntity(id: UUID(), title: "The Lord of the Rings"), ]
3
0
1k
Aug ’23
App Intents with OpensIntent does not work correctly
We are developing an app for iOS 16 using App Intents and Siri. We have been testing the behavior of opening another App Intent by passing the opensIntent argument to the result function in the App Intent with iOS 16.4 devices. As a result, we found that the dialog text specified in the result argument of the Intent to which it transitions is not displayed and therefore does not work. And also found that when invoked from Siri, the Intent passed to the opensIntent argument is invoked "twice". Are these behaviors bugs? Any ideas? The following is a sample code and logs. import AppIntents struct PrimaryIntent: AppIntent { static var title: LocalizedStringResource = "Primary" func perform() async throws -> some OpensIntent { print("\(String(describing: Self.self)).\(#function): invoked") return .result(opensIntent: SecondaryIntent()) } } struct SecondaryIntent: AppIntent { static var title: LocalizedStringResource = "Secondary" func perform() async throws -> some ProvidesDialog { print("\(String(describing: Self.self)).\(#function): invoked") return .result(dialog: .init(stringLiteral: "test")) } } struct ShortcutsProvider: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut(intent: PrimaryIntent(), phrases: ["\(.applicationName)"]) } } logs from Shortcut App PrimaryIntent.perform(): invoked SecondaryIntent.perform(): invoked # is not displayed dialog... logs from Siri PrimaryIntent.perform(): invoked SecondaryIntent.perform(): invoked SecondaryIntent.perform(): invoked # is not displayed dialog... # SecondaryIntent invoked twice...
1
1
1.5k
Aug ’23
How to create App Shortcut just like New Note from Notes app
In iOS 17 when you search Spotlight for Notes you can see it has an App Shortcut titled New Note that simply opens the Notes app and starts composing a new note. When you open the Shortcuts app, create a new shortcut, search for and tap Notes, notice the New Note action is ONLY included at the top - it's not in the list of actions underneath. There is another intent in the list titled Create Note which will create a new note using the content you specify without opening the Notes app. I want to achieve this same thing in my app - an App Shortcut to open the app and start creating a new item, and a shortcut action to create a new item without opening the app. How can this be done? So far I have created two AppIntents, NewItem and CreateItem. My AppShortcutsProvider only includes NewItem. This works great when searching for my app in Spotlight. But when I open Shortcuts and go to add an action from my app to a shortcut, it includes Add Item at the top as an App Shortcut but also in the actions list underneath. Create Item is included in the list as well which is confusing. I don't want Add Item to be an available action because it's fairly useless to open the app and start creating an item, instead they should use Create Item to create an item in the background. Do I need to instead create a single shortcut that behaves differently in Spotlight vs Shortcuts, is that possible?
0
2
939
Aug ’23
AppShortcuts error: Command ValidateAppShortcutStringsMetadata emitted errors
In Xcode 15 beta 3 and beta 4, if you add a AppShortcuts.xcstrings catalog or legacy AppShortcuts.strings files to the project, the project will always fail to build due to the following error. error: Unable to call validation: The data couldn’t be read because it isn’t in the correct format. (in target 'LearnAppShortcuts' from project 'LearnAppShortcuts') Command ValidateAppShortcutStringsMetadata emitted errors but did not return a nonzero exit code to indicate failure The error seems related to a cli called ValidateAppShortcutStringsMetadata. Reproducing Steps (1) In Xcode 15 beta 3/4, create a new iOS app project. (2) Add an arbitrary AppIntent and AppShortcutsProvider. import AppIntents struct MyAction: AppIntent { static let title: LocalizedStringResource = "My Action" func perform() async throws -> some IntentResult { return .result() } } struct MyAppShortcts: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut(intent: MyAction(), phrases: [ "Perform action with \(.applicationName)" ], shortTitle: "Perform My Action", systemImageName: "heart") } } (3) Create a new AppShortcuts.xcstrings catalog file and add it to the iOS target (4) Build the project. The string catalog will be updated as expected. However, the build will fail.
3
0
868
Aug ’23
Condition on AppShortcutsProvider
I'm building an new App Intent that I'm planning to add to the list of AppShortcuts provided by my app, however this new Intent will only work for users on iOS 17. Is it possible to add this new Intent only for users on the newer version? The AppShortcutsProvider doesn't seem to support conditionals and I don't wan't to drop support of my current AppShortcuts for users or previous versions. I've also tried returning an array of AppShortcuts to the provider instead of using the AppShortcutsBuilder, but then no App Shortcuts are displayed on the Shortcuts app. Has anyone ran into this issue before? Thanks for the help
0
0
552
Aug ’23
Optional Parameter using WidgetConfigurationIntent
Hi there, I'm adding a new widget using the new WidgetConfigurationIntent which takes a number of parameters, including one which conforms to AppEntity. It is defined as an optional. When the user is configuring the widget, after one of the suggested entities is chosen, there is no way to return to a state where this value is nil. Is this possible? I'd like the user to be able to select "None" for this parameter. For now, I'm using a bool to determine whether the AppEntity parameter is used. Thanks!
1
0
671
Aug ’23
Xcode 14 Automatic signing failed
I have added Siri capability for an iOS/MacCatalyst app in Xcode. The app compiles just fine for iOS, but when compiling for MacCatalyst I get the error: “/Volumes/xdrive/M2/M2.xcodeproj Provisioning profile "Mac Catalyst Team Provisioning Profile: com.anotherview.M2.mac" doesn't include the com.apple.developer.siri entitlement. ” On the “Signing & Capabilities” page I get the error: “Automatic signing failed Xcode failed to provision this target. Please file a bug report at https://feedbackassistant.apple.com and include the Update Signing report from the Report navigator.” How can I add Siri capabilities on a Mac Catalyst app?
0
0
717
Aug ’23
shortCuts
struct MeditationShortcuts: AppShortcutsProvider { AppShortcut( intent: OCRIntent(), phrases: [AppShortcutPhrase<OCRIntent>.init("OCR识别\(AppShortcutPhraseToken.applicationName)")], shortTitle: "文字识别", systemImageName: "checklist" ) } static var shortcutTileColor: ShortcutTileColor { return .orange } } Why packaging shortcut instructions in the above way will not be displayed in the shortcut instruction app? Defining a phrase in literal terms will show, for example struct MeditationShortcuts: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut( intent: OCRIntent(), phrases: ["OCR识别\(.applicationName)"], shortTitle: "文字识别", systemImageName: "checklist" ) } static var shortcutTileColor: ShortcutTileColor { return .orange } }
0
0
309
Aug ’23
Code Examples for starting background audio from an AppIntent
Hi all, I'm trying to update my app to use the AppIntent framework to play an audio file (loaded from the main bundle). I tried implementing an a PlayMusicIntent using the AudioStartingIntent protocol, but have had no luck. The intent does run, and provides the dialog response, but the music doesn't start. struct PlayMusicIntent: AudioStartingIntent { static let title:LocalizedStringResource = "Play Music" @MainActor func perform() async throws -> some IntentResult & ProvidesDialog { guard let musicPath = Bundle.main.url(forResource: "moonglow", withExtension: "mp3") else { fatalError("Could not load music file") } do { let musicPlayer = try AVAudioPlayer(contentsOf: musicPath) musicPlayer.numberOfLoops = -1 musicPlayer.play() return .result(dialog: "Now Playing Moonglow") }catch { print(error) return .result(dialog: "There was an error playing the music: \(error.localizedDescription)") } return .result(dialog: "Cannot play music") } } And then add this in my App Shortcuts Provider: AppShortcut(intent: PlayMusicIntent(), phrases: [ "Play music with \(.applicationName)" ]) I do have Audio background mode enabled. I'm thinking I need to do something with the intent's return type, but there is not a lot of documentation or online examples to implement AudioStartingIntent Any suggestions would be appreciated. Thanks, Scott
3
1
1.4k
Aug ’23
AppIntentTimelineProvider in iOS17 Beta 4
I'm back from vacation and installed iOS Beta 4 and with that my Widgets stop working :( Funktions func snapshot(for configuration: ConfigurationIntent, in context: Context) async -> MyTeslaWidgetEntry {} func timeline(for configuration: Intent, in context: Context) async -> Timeline<Entry> {} are never called. Instead I get this warnings inside the console: No AppIntent in timeline(for:with:) No AppIntent in snapshot(for:with:) But there are no functions with parameter "for"... What is the problem here?
0
0
617
Aug ’23
AppIntent is not notifying MainApp With NSUserActivity in UIKit
This is Siri Intent before iOS 16. func handle(intent: CustomIntent, completion: @escaping (CustomIntentResponse) -> Void) { completion(CustomIntentResponse(code: .continueInApp, userActivity: nil)) } This flow working fine. This is AppIntent after iOS 16. There are 2 ways to continue in app openAppWhenRun = true ForegroundContinuableIntent Protocol only works in SwiftUI But both are not notifying the main app its just opening app without activity. In SiriIntent we can notifiy Main App with completion(CustomIntentResponse(code: .continueInApp, userActivity: nil)) application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool else its start with didfinishlaunching and we can get useractivity. Is there any solution for after iOS 16 In AppIntent we can notify app and get NSUserActivity?
2
3
763
Jul ’23
AppIntents that show a Snippet View cannot use SF symbols
Several of the shortcuts in our App show a Snippet View. This is just a regular SwiftUI View with some text and a SF symbol. The preview works fine, tapping the shortcut in the Shortcuts App works fine, and tapping the shortcut in Spotlight works fine; in all these cases, both the text and the SF symbol are shown as expected. But when the shortcut is run by speaking a phrase using Siri, the snippet shows the text but the SF symbol is not shown. Has anyone come across this issue? This is happening on both iOS 16 and the latest iOS 17 beta (Beta 4). There are numerous errors in the logs all repeating the same error message: No symbol named 'exclamationmark.triangle.fill' found in system symbol set Here is the code for the Snippet View: struct StatusSnippetView: View { let status: String var body: some View { VStack { Image(systemImage: "exclamationmark.triangle.fill") .resizable() .aspectRatio(contentMode: .fit) .frame(height: 48) Text(status) .font(.headline) } } } Errors seen in the console: 2023-07-27 00:43:51.407698-0400 Kevo[56745:6956239] [framework] CoreUI: -[CUICatalog namedVectorGlyphWithName:scaleFactor:deviceIdiom:layoutDirection:glyphSize:glyphWeight:glyphPointSize:appearanceName:] 'exclamationmark.triangle.fill' called with scaleFactor == 0.000000 glyphPointSize == 16.000000 at '/System/Library/PrivateFrameworks/SFSymbols.framework/CoreGlyphs.bundle/Assets.car' 2023-07-27 00:43:51.407855-0400 Kevo[56745:6956239] [framework] CoreUI: -[CUICatalog namedVectorGlyphWithName:scaleFactor:deviceIdiom:layoutDirection:glyphSize:glyphWeight:glyphPointSize:appearanceName:] 'exclamationmark.triangle.fill' called with scaleFactor == 0.000000 glyphPointSize == 16.000000 at '/System/Library/PrivateFrameworks/SFSymbols.framework/CoreGlyphs.bundle/Assets.car' 2023-07-27 00:43:51.407944-0400 Kevo[56745:6956239] [framework] CoreUI: -[CUICatalog namedVectorGlyphWithName:scaleFactor:deviceIdiom:layoutDirection:glyphSize:glyphWeight:glyphPointSize:appearanceName:] 'exclamationmark.triangle.fill' called with scaleFactor == 0.000000 glyphPointSize == 16.000000 at '/System/Library/PrivateFrameworks/SFSymbols.framework/CoreGlyphs.bundle/Assets.car' 2023-07-27 00:43:51.407994-0400 Kevo[56745:6956239] [framework] CoreUI: -[CUICatalog namedVectorGlyphWithName:scaleFactor:deviceIdiom:layoutDirection:glyphSize:glyphWeight:glyphPointSize:appearanceName:] 'exclamationmark.triangle.fill' called with scaleFactor == 0.000000 glyphPointSize == 16.000000 at '/System/Library/PrivateFrameworks/SFSymbols.framework/CoreGlyphs.bundle/Assets.car' No symbol named 'exclamationmark.triangle.fill' found in system symbol set
1
2
495
Jul ’23
Xcode 15 beta 5 + iOS 17 beta 4: AppShortcuts do not show up in Shortcuts app
In Xcode 15 beta 5 + iOS 17 beta 4, the AppShortcuts (or maybe Shortcuts app) is broken. The AppShortcuts defined in AppShortcutsProvider are not shown up in the Shortcuts app any more. Reproduce Code import SwiftUI import AppIntents @main struct LearnShortcutsApp: App { var body: some Scene { WindowGroup { Text("Hello, world!") } } } struct MyAction: AppIntent { static let title: LocalizedStringResource = "My Action" func perform() async throws -> some IntentResult { return .result() } } struct MyAppShortcts: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut(intent: MyAction(), phrases: [ "Perform action with \(.applicationName)" ], shortTitle: "Perform My Action", systemImageName: "heart") } }
1
1
557
Jul ’23