Share intents from within an app to drive system intelligence and show the app's actions in the Shortcuts app.

Posts under Intents tag

69 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Why does my SwiftUI app crash when opened from an intent?
I'm encountering a crash in my SwiftUI app when it is opened via an AppIntent. The app runs perfectly when launched by tapping the app icon, but it crashes when opened from an intent. Here is a simplified version of my code: import AppIntents import SwiftData import SwiftUI @main struct GOGODemoApp: App { @State private var state: MyController = MyController() var body: some Scene { WindowGroup { MyView() //.environment(state) // ok } .environment(state) // failed to start app, crash with 'Dispatch queue: com.apple.main-thread' } } struct MyView: View { @Environment(MyController.self) var stateController var body: some View { Text("Hello") } } @Observable public class MyController { } struct OpenIntents: AppIntent { static var title: LocalizedStringResource = "OpenIntents" static var description = IntentDescription("Open App from intents.") static var openAppWhenRun: Bool = true @MainActor func perform() async throws -> some IntentResult { return .result() } } Observations: The app works fine when launched by tapping the app icon. The app crashes when opened via an AppIntent. The app works if I inject the environment in MyView instead of in WindowGroup. Question: Why does injecting the environment in WindowGroup cause the app to crash when opened from an intent, but works fine otherwise? What is the difference when injecting the environment directly in MyView?
0
0
55
2d
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
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
Type '' does not conform to protocol '_IntentValue' - AppIntents
Hi there. First time poster! I'm attempting to implement App Intents in my app, as part of the App Intent I have included a parameter requiring the user specify one of their 'to do lists'. @Parameter(title: "List", description: "One of your Marvelist lists.") var list: MarvelistModels.List However, I'm receiving the below error in Xcode... Type 'MarvelistModels.List' does not conform to protocol '_IntentValue' When I go to the struct for MarvelistModels.List, and attempt to make it conform to _IntentValue, it adds typealias Specification = type to my struct... however, I can't quite figure out how to make it conform. Any help/advice would be greatly appreicated!
1
1
305
6d
Handling App Intents Behind Authentication/Paywall
My App has several resources that I'd like to spring open through App Intents. For example a series of Dictionaries. These resources however in the app are behind a log in (for security) and are entitlements that are purchased. They may own 4 of 7 dictionaries. If I want to have an intent that says, "Open Dictionary: (Dict Name)" how do I best handle situations where the user may no longer be logged in or have the entitlement for that specific dictionary? Thanks
1
0
251
Jun ’24
How can I include app intents only for newer OS versions?
I have an app that currently supports as low as iOS 16. I'd like to add some app intents to it that allow customization using the WidgetConfigurationIntent API that's only available on iOS 17 and later. Is there a way to build an intent (or other kind of app extension) that requires a higher OS version than my main app's deployment target, and only surface it for those OS versions?
0
0
211
Jun ’24
Unexpected URLRepresentableIntent behaviour
After watching the What's new in App Intents session I'm attempting to create an intent conforming to URLRepresentableIntent. The video states that so long as my AppEntity conforms to URLRepresentableEntity I should not have to provide a perform method . My application will be launched automatically and passed the appropriate URL. This seems to work in that my application is launched and is passed a URL, but the URL is in the form: FeatureEntity/{id}. Am I missing something, or is there a trick that enables it to pass along the URL specified in the AppEntity itself? struct MyExampleIntent: OpenIntent, URLRepresentableIntent { static let title: LocalizedStringResource = "Open Feature" static var parameterSummary: some ParameterSummary { Summary("Open \(\.$target)") } @Parameter(title: "My feature", description: "The feature to open.") var target: FeatureEntity } struct FeatureEntity: AppEntity { // ... } extension FeatureEntity: URLRepresentableEntity { static var urlRepresentation: URLRepresentation { "https://myurl.com/\(.id)" } }
1
1
327
2w
Migrating custom intents to App Intents
Hi, I am trying to migrate my custom intents to App Intents, and was running into some issues. My current intentdefinitions file and all intent handling code are in a framework that is shared with my app target. I went through the migration assistant and added the App Intents codes directly to my main app target. When I run a shortcut with the App Intent, it doesn't work ... I get some messages in the console that say: Could not find an intent with identifier MyCustomAddContactIntent, mangledTypeName: Optional("") I guess the old custom intents and new App Intents should both live in the same package to see each other. In this case, I'm not sure if all the existing custom intents file and all the intents handler logic should be moved into the main app bundle (and removed from framework), or should I add the new App Intents handlers into the framework (in addition to the main app)? Also, will the custom framework even be needed or run in iOS16+? Thanks.
0
0
257
Jun ’24
Are suggested Play Media Intents no longer shown on lock screen?
Play media intents suggested via INUpcomingMediaManager.setSuggestedMediaIntents(_:) have been shown on the iOS lock screen in past iOS versions. In iOS 16/17 play media intents seem to be only shown within the Siri suggestions in the spotlight overlay and in the Siri suggestion widget. When the intents were shown on the lock screen, it was possible to open a preview via long press. Similar to notification previews. Preview support could be implemented with an Intents UI extension. Is there still any place in current iOS versions where play media intents are surfaced and a preview can be opened? In the spotlight overlay a long press has no effect.
0
0
257
May ’24
Can we add an action to the 'Shortcuts' app in macOS using 'Intents extension'?
I have macOS application and I want to provide an action for it in the 'Shortcuts' app QuickAction list. I was using InApp handling to present my intent created in the intent.intentdefinition file as action in the shortcuts app and it was working. However, this action perform a very lightweight task so I intent to have the action implemented as an extension in my xcode project. According to my minimum deployment(i.e macOS 11.0) I found that 'Intents Extension' could be used. I have added the 'Intents extension' target to my main application and created an intent using the intent.intentdefinition file. However, my intent does not appear in the shortcuts app. I have verified it multiple time to ensure I am not missing anything, but still the intent is not present in the shortcuts app action. I wanted to be know, Is this even possible? cause this apple documentation only mentions about iOS and watchOS app. It also does not mention If our custom intent(created using Intents extension) in the intents extension can be exposed to the shortcuts app. For macOS 13.0+, I have used the 'AppIntents extension' and I m able to achieve the same. So, I suppose the same should be possible using the 'Intents extension'
1
0
293
May ’24
'openAppWhenRun' property causing AppIntentsExtension to fail
I have added an "App Intents Extension" target to my main application in macOS. This generated the below two files: TWAppIntent.swift import AppIntents struct TWAppIntent: AppIntent { static var title: LocalizedStringResource = "TWAppIntentExtension" static var parameterSummary: some ParameterSummary { Summary("Get information on \(\.$TWType)") } //launch app on running action static var openAppWhenRun: Bool = true // we can have multiple parameter of diff types @Parameter(title: "TWType") var TWType: String func perform() async throws -> some IntentResult & ReturnsValue<String> & ProvidesDialog { return .result(value: TWType, dialog: "Logged break.") } } TWAppIntentExtension.swift import AppIntents @main struct TWAppIntentExtension: AppIntentsExtension { } I m able to build the extension target and I my intent action is available in the shortcuts app. However, on launching a shortcut with the above created intent action. I m getting the below popups: I have identified what is causing this error. Setting the openAppWhenRun to true is causing this error. I don't get this when it is set to false. This property is supposed to launch the application, but can someone help me understand why is it happening? This is only causing the error when using this property for AppIntent Extension and not for In app handling for the AppIntent. Can we not launch our application from AppIntent extension?
1
2
305
May ’24
Calling AppIntent Siri Voice Issue
Hello, I have an app with two AppIntents. I invoke first AppIntent with my voice command, then I would like invoke the second AppIntent after the first one. I have implemented the necessary return type for the first AppIntent. My first AppIntent is invoked and executes successfully, however when it calls the second AppIntent, everything inside perform() method in the second AppIntent works but Siri dialog. Siri doesn't say the dialog in the second AppIntent. Below implementation details for my two AppIntents together with AppShortcutsProvider. I appreciate any help. struct MyFirstAppIntent : AppIntent { static let title: LocalizedStringResource = "Show My Usages" func perform() async throws -> some ProvidesDialog & OpensIntent { let dialogStr = IntentDialog(stringLiteral: "You have a package") print("I'm in first AppIntent") return .result(opensIntent: MySecondAppIntent(), dialog: dialogStr) } struct MySecondAppIntent: AppIntent { static let title: LocalizedStringResource = "Show My Usages" func perform() async throws -> some IntentResult & ReturnsValue<String> & ProvidesDialog { print("I'm in second AppIntent") return .result(value: "Listing Packages", dialog: "You have activated Default") } struct MyVoiceShortcutProvider : AppShortcutsProvider { @AppShortcutsBuilder static var appShortcuts: [AppShortcut] { AppShortcut( intent: MyFirstAppIntent(), phrases: ["Call my first intent \(.applicationName)"] ); AppShortcut( intent: MySecondAppIntent(), phrases: ["Call my second intent \(.applicationName)"] ); } }
0
0
306
May ’24