App Intents

RSS for tag

Extend your app’s custom functionality to support system-level services, like Siri and the Shortcuts app.

App Intents Documentation

Posts under App Intents tag

165 Posts
Sort by:
Post not yet marked as solved
1 Replies
270 Views
If an app contains app intents and built using the visionOS 1.1 SDK, and the app is either run on the visionOS 1.0 simulator or a visionOS 1.0 device the app instantly crashes on launch with a missing symbol error. This doesn’t happen with apps built using the visionOS 1.0 SDK. Below is a screenshot of a crash report sent by TestFlight review: Feedback ID: FB13666685
Posted
by
Post not yet marked as solved
0 Replies
349 Views
I have an Intents definition file for a Custom Intent that I want to convert to an AppIntent. The Custom Intent has the checkbox "Configurable in Shortcuts" not checked and therefore the "Convert to App Intent" Button is greyed out. I can however still do a conversion using the Menu-Item "Editor"->"Convert to App Intent". The intent has a number of parameters that are not configurable, but were set in code. This way it was possible to donate shortcuts with the parameters (and even the title) set in code. The automatic conversion using the menu item however produces a result that does not match the legacy Custom Intent (Parameters appear in the Shortcuts App etc). I also did not find any way to create AppIntents that have parameters that can be set in code, before the intent is donated. I would leave the old legacy Custom Intents as they are, but as soon as make use of any of the new iOS 16 Shortcut features (App Shortcuts) the existing donated Custom Intents disappear in the Shortcuts App. Given the apparent inability to convert them into AppIntents due to the missing code-set parameters, I would be happy for any advice on potential solutions.
Posted
by
Post not yet marked as solved
2 Replies
362 Views
Hi! I have an AppShortcutsProvider that has been marked @available(iOS 17.0, *), because all Intents used within it are only available in iOS 17. So the static var appShortcuts should only be accessible in iOS 17, obviously. Now this code has been released and works fine for iOS 17 users. But I just noticed that around 150 iOS 16 users have crashed in the static var appShortcuts, or more specifically, the defaultQuery of one of the Intents. This should not be possible, as neither the AppShortcutsProvider, nor the Intent is exposed to iOS 16, they are marked as @available(iOS 17.0, *). Any idea why this could happen? Here is the crash log: Crashed: com.apple.root.user-initiated-qos.cooperative 0 libswiftCore.dylib 0x3e178c swift::ResolveAsSymbolicReference::operator()(swift::Demangle::__runtime::SymbolicReferenceKind, swift::Demangle::__runtime::Directness, int, void const*) 1 libswiftCore.dylib 0x40bec4 swift::Demangle::__runtime::Demangler::demangleSymbolicReference(unsigned char) 2 libswiftCore.dylib 0x408254 swift::Demangle::__runtime::Demangler::demangleType(__swift::__runtime::llvm::StringRef, std::__1::function<swift::Demangle::__runtime::Node* (swift::Demangle::__runtime::SymbolicReferenceKind, swift::Demangle::__runtime::Directness, int, void const*)>) 3 libswiftCore.dylib 0x3e9680 swift_getTypeByMangledNameImpl(swift::MetadataRequest, __swift::__runtime::llvm::StringRef, void const* const*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) 4 libswiftCore.dylib 0x3e4d9c swift_getTypeByMangledName 5 libswiftCore.dylib 0x3e50ac swift_getTypeByMangledNameInContext 6 MyApp 0x3f6b8c __swift_instantiateConcreteTypeFromMangledName (<compiler-generated>) 7 MyApp 0x640e3c one-time initialization function for defaultQuery + 146 (IntentAction.swift:146) 8 libdispatch.dylib 0x3eac _dispatch_client_callout 9 libdispatch.dylib 0x56ec _dispatch_once_callout 10 MyApp 0x64109c protocol witness for static AppEntity.defaultQuery.getter in conformance IntentAction + 124 (IntentAction.swift:124) 11 AppIntents 0x15c760 _swift_stdlib_malloc_size 12 AppIntents 0x19dfd4 __swift_destroy_boxed_opaque_existential_1Tm 13 MyApp 0x52dadc specialized ActionIntent.init(action:) + 41 (ActionIntent.swift:41) 14 MyApp 0x52df80 specialized static MyShortcuts.appShortcuts.getter + 17 (MyShortcuts.swift:17)
Posted
by
Post marked as solved
2 Replies
332 Views
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 = "TWAppIntent" static var parameterSummary: some ParameterSummary { Summary("Get information on \(\.$TWType)") } // we can have multiple parameter of diff types @Parameter(title: "TWType") var TWType: String func perform() async throws -> some IntentResult { return .result(dialog: "Executed TWAppIntent.") } } 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: From what I understand, I m getting this error because I have not added my 'TWAppIntent' to the TWAppIntentExtension.swift file which is the entry point for the extension, but I could not find any documentation around how to add it. Can someone help on how to do it or Is there something else that I m doing wrong?
Posted
by
Post not yet marked as solved
0 Replies
287 Views
Hello. My project includes a widget target that provides interactive widget functionalities. The document "Adding Interactivity to Widgets and Live Activities" says the following: Additionally, note that the perform() function is marked as throws. Be sure to handle errors instead of rethrowing them, and update your app, widget, and Live Activity as needed. For example, update a widget’s interface to indicate that it displays outdated information if it cannot load new data. https://developer.apple.com/documentation/widgetkit/adding-interactivity-to-widgets-and-live-activities#Implement-the-perform-function, column 3 However, I couldn't find a way how to handle an error in an interactive widget. The Button(intent:) and Toggle(intent:) initializers don't have mechanisms for error handling. Does anyone know a solution for handling errors in interactive widgets?
Posted
by
Post not yet marked as solved
0 Replies
284 Views
Adding the AppIntent of my app as AppShortcuts to the Shortcuts Apps was easy. This only required an AppShortcutsProvider. However, I am confused how the AppShortcuts are shown in the Shortcuts App. It seems that there are different styles enter image The AppShortcuts of some apps are shown as tiles While shortcuts from other apps are shown as collection of circle icons Some "circle collection" use a default gray background with blue icons Others color or even gradient backgrounds with white icons The only thing I found that might be related to the design is the shortcutTileColor property in the AppShortcutsProvider. However using/changing this property has no effect on how my app's shortcus are shown: On the default gray background / blue icon. Among the different apps on my devices I cannot see any logic which shortcuts are shown as tiles and which as circle icons. Additionally third party apps use colored background or gradients. So there there has to be a way to change this. But how?
Posted
by
Post not yet marked as solved
0 Replies
284 Views
AppIntens can be used as actions when working with Shortcut Automation. iOS offers a bunch of different triggers to start an automation, such as "Time of Day", "Email", "Transaction", etc. Depending on the trigger one can then pass different "Shortcut input" values as parameters to the App Intent. While in many cases the expected type is quite obvious, this is not always the case. An Email type input for example offers Subject, Sender, Recipients, Attachments, Content, Name. Subject will be most likely a String. But is Sender also a String or maybe an IntentPerson? Is Recipients a String (e.g. comma separated) or a collection? Is Attachments a [String], [URL] or [IntentFile]? How to I find out of which types these inputs have? Is there a better way than guessing and trial and error? The documentation provides very little information about supported types in general and I could find nothing about the types used by different triggers. Additionally each "Shortcut input" offers it self as parameter. So the Email type input does not only offer Subject, Sender, etc. as input parameters but also Email. What parameter type does an intent need no accept in order to receive on Email object? Thank you very much for your help.
Posted
by
Post not yet marked as solved
0 Replies
347 Views
The Shortcuts app offers the possibility to trigger shortcuts/intends when a wallet credit card is used and a new transaction is created. I would like to add transaction details to one of my apps and use such a shortcut for it. Other apps do the exact same thing, so this should not be a problem. Adding a shortcut to my app was not a big deal. However, how can this be tested on simulator? When trying to add a new automatization in the Shortcuts app using a wallet transaction as trigger I cannot finish the setup dialog since the Next button is disabled. I assume this is because no card is configured. When trying to add a card in Wallet I just receive that this was not successful. I have connected the simulator to a Sandbox Apple ID account using a region which supports Apple Pay (US). Using a real account does not solve the problem. Any idea how to get this working? Using real transaction within a store could obviously not be the solution for debugging.
Posted
by
Post marked as solved
1 Replies
391 Views
In my app, there's a widget that should change to one color when clicked and then to another color after 10 seconds. When I click the widget button (linked to the App Intent), the widget should refresh. When I debug, this happens as expected. However, if I call WidgetCenter.shared.reloadAllTimelines() in the perform() method of AppIntent, the widget timeline doesn't refresh right away. This issue only happens on real devices and isn't always consistent. In the simulator, the widget refreshes as expected.
Posted
by
Post not yet marked as solved
0 Replies
304 Views
I show some content in LiveActivity Dynamic Island and added a button. As buttons work with App Intent I created an Intent. When the button is clicked I get the following error Could not find an intent with identifier MyIntent, mangledTypeName: Optional("19LiveWidgetExtension10MyIntentV") MyIntent.swift import Foundation import AppIntents struct MyIntent: LiveActivityIntent { public init() { } func perform() async throws -> some IntentResult { print("click") return .result() } } MyLiveActivity.swift ... DynamicIslandExpandedRegion(.bottom) { HStack(alignment: .top) { Button(intent: MyIntent()) { Image(systemName: "bolt.fill") } } .tint(.white) .padding() } .... The Intent is added to all targets. Any ideas?
Posted
by
Post not yet marked as solved
0 Replies
240 Views
Hello guys Im searching a way to create, or to use an existent shortcut to limit timetables for certain applications. My goal is not to limit the daily maximum time for using an application. An example: my Iphone would not permit me to use tiktok from 6.00 AM to 8.00 AM Thank you in advance
Posted
by
Post not yet marked as solved
0 Replies
344 Views
Recently I realized that even though I was able to add my app's intents in the Shortcuts app, selecting any of the parameters didn't show the popup list of suggestions (the ones declared by DynamicOptionsProvider in the AppIntent subclass) and running it showed an error. In the image you can see the two suggestions for the working app version ("asdf" and "bla") that would not be there in the non-working version. I knew that when I had added this functionality, it worked, so I found the app version that caused the App Intents Extension to stop working. Apparently, the problem was that I had removed the Swift files declared in the app extension from my main app's target. Probably when I first added the App Intents Extension I had noticed that adding the extension's source files to the main target made it work, but later thought that it shouldn't be necessary and didn't test if it still worked. Today I created an empty project with a new App Intents Extension and confirmed that the Shortcuts app was correctly showing the parameter popup suggestions, even without including the extension's source files in the main target. Then during the course of almost an entire day I gradually reduced my original Xcode project to this new sample project to find what else would make the extension work, other than including the extension's source files in the main target. My very last resource was changing the bundle identifier, which solved the issue. My original project's targets have identifiers like org.domain.OriginalApp and org.domain.OriginalApp.AppIntent, while the sample project's targets have identifiers like org.domain.SampleApp and org.domain.SampleApp.AppIntent. How could including the App Intents Extension's source files in the main target or changing the bundle identifiers cause the Shortcuts app to correctly show the parameter popup suggestions?
Posted
by
Post not yet marked as solved
0 Replies
272 Views
Is it possible to get the original date created for an IntentFile? The following code always gets the date for right now, surely because it's copied into a temporary directory so that's when it was created at that location. if let fileURL = file.fileURL, fileURL.startAccessingSecurityScopedResource() { if let attributes = try? FileManager.default.attributesOfItem(atPath: fileURL.path), let date = attributes[.creationDate] as? Date { print(date) } fileURL.stopAccessingSecurityScopedResource() }
Posted
by
Post not yet marked as solved
0 Replies
223 Views
Sorry if I'm in the wrong category for this :pray: Please see this MRE for clarity: https://github.com/MartinP7r/IntentTest (I used the example code from https://developer.apple.com/wwdc22/10032 except for deprecation warnings) The compiler throws an error Unable to determine value type for type IntentPackage.Shelf. According to comments in this question it's because the type I'm extending to AppEnum is not in the app target's module, but in a Swift Package. And yes, copying Shelf into the target will solve the issue, but I really don't like having to duplicate the types just to make it work and was wondering if there's any way to just use the type from the Swift package and only add the AppEnum conformance in the main target.
Posted
by
Post not yet marked as solved
1 Replies
339 Views
How to disable iOS Shortcut ( Automation ) Programmatically ? I have made an automation to open my app whenever a user opens Facebook app. When the user taps on "Continue with Facebook" the automation which is forcing to open my App show be disabled for 2 minutes. How can I achieve this?
Posted
by
Post not yet marked as solved
0 Replies
257 Views
Hello Community, I recently started to work on shortcuts with AppIntent and I want to have an image output on my shortcut action. The output of a string is simple and working: func perform() async throws -> some IntentResult & ReturnsValue<String> { let myString : String = "Hello World" return .result(value: myString) I am having trouble to return an image. Ideally I want to load an image from iCloud Drive or from a website and throw image result. I tried func perform() async throws -> some IntentResult & ReturnsValue<Image> { and func perform() async throws -> some IntentResult & ReturnsValue<INFile> { , but was not apple to write a proper code to return .result(value: myImage) . Any help is very welcome and highly appreciated. Have a good week Eric
Posted
by
Post not yet marked as solved
0 Replies
305 Views
@MainActor perform() async throws -> some IntentResult { // ... switch locationManager.authorizationStatus { case .denied, .restricted: throw UserLocationError.permissionDenied case .notDetermined: await locationManager.requestWhenInUseAuthorization() // to ask permission default: break } // ... } Here is my code. When the authorizationStatus is .notDetermined, it invokes requestWhenInUseAuthorization() method on the main thread, but throws UserLocationError.permissionDenied immediately, eventhough I didn't deny the permission. It's really weird and unexpected that it throws UserLocationError.permissionDenied when the status is not .denied or .restricted Even it invokes requestWhenInUseAuthorization(), there's no alert for asking permission If there's any solution, please let me know
Posted
by
Post not yet marked as solved
2 Replies
563 Views
Hello everyone, I want to add preconfigured app shortcuts for my app using an AppShortcutsProvider implementation. I have been following this demo from WWDC22: https://developer.apple.com/wwdc22/10170 All looks pretty straight forward. However, I would like the preconfigured shortcuts to be based on the state of the data in the app: adding one shortcut for every user-entered item in a list. Now, this might be due to the fact that I'm a Swift novice, but I can't figure out how to do that from a AppShortcutsBuilder property as I can't create the AppShortcut instances in a for loop. I have failed to find any resources online on this. I assume I would need the ForEach equivalent of the ViewBuilder? Is anything like that available for AppShortcutsBuilder? I have also stumbled on this: https://developer.apple.com/documentation/sirikit/offering_actions_in_the_shortcuts_app But this solution seems to only work with INIntents rather than AppIntents. Is there a setShortcutSuggestions equivalent for AppIntents that I could call when the contents of my list change?
Posted
by
Post not yet marked as solved
0 Replies
463 Views
Hello, I'm working on my first app. It's also my first encounter with App Intents. I have a data structure for events that has an ID (String), a name (String), a Date and an image (Data). The user can create them in the app and they are stored with CoreData. I wanted to have a widget that would allow the user to choose from their list of events and display that event in the widget. The list should appear in the widget configuration and it would be a list of the names and (if possible) the image. I think I have found how to access the information from the widget, but I cannot figure out how to have the list appear in the configuration. I have been following this guide: https://developer.apple.com/documentation/widgetkit/making-a-configurable-widget?utm_source=pocket_saves. But that one shows hardcoded elements in the list and I haven't been able to find how to have the list change in relation to the content of the app. This is what I have made so far in the AppIntent file: import WidgetKit import AppIntents import CoreData struct EventDetail: AppEntity { static var defaultQuery: EventQuery = EventQuery() var id: String var date: Date var image: Data var title: String static var typeDisplayRepresentation: TypeDisplayRepresentation = "Event" var displayRepresentation: DisplayRepresentation { DisplayRepresentation(title: "\(id) \(title)") } } struct EventQuery: EntityQuery{ func entities(for identifiers: [EventDetail.ID]) async throws -> [EventDetail] { return fill_event_details(events_list: getEventDataIntent()) } func suggestedEntities() async throws -> [EventDetail] { fill_event_details(events_list: getEventDataIntent()).filter { $0.id != "-" } } func defaultResult() async -> EventDetail? { try? await suggestedEntities().first } } struct ConfigurationAppIntent: WidgetConfigurationIntent { static var title: LocalizedStringResource = "Select an event" static var description = IntentDescription("This is an example widget.") // An example configurable parameter. @Parameter(title: "Event") var event: EventDetail // init(events: [UserCountdowns]) { // self.event = fill_event_details(events_list: events)[0] // print("AppIntent") // print(self.event.title) // } init() { } } func fill_event_details(events_list: [UserCountdowns]) -> [EventDetail] { var entities_list: [EventDetail]? let events = getEventDataIntent() for event in events { entities_list!.append(EventDetail(id: event.id!, date: event.date!, image: event.image!, title: event.title!)) } return entities_list ?? [EventDetail(id: "-", date: Date(), image: Data(), title: "empty")] } func getEventDataIntent() -> [UserCountdowns] { let context = PersistenceController.shared.container.viewContext let request = UserCountdowns.fetchRequest() var result: [UserCountdowns]! do { result = try context.fetch(request) } catch { print(error) } return result } I have been trying a few things in the widget's code but I haven't been able to make anything work, so I don't really have anything worth sharing, I think. This is the code for the UserCountdowns structure: extension UserCountdowns { @nonobjc public class func fetchRequest() -> NSFetchRequest<UserCountdowns> { return NSFetchRequest<UserCountdowns>(entityName: "UserCountdowns") } @NSManaged public var date: Date? @NSManaged public var image: Data? @NSManaged public var title: String? @NSManaged public var id: String? } Could anyone help me with this, please? What am I missing or what would the next step be? Let me know if there is any other part of the code I should share. Thank you in advance!
Posted
by