I have AppIntent code which lives in my app package that can not easily be decoupled and migrated into its own standalone framework or extension. This is because this intent has some action that relies on my app's network and core data stack. I'd like to expose this existing intent in some way to a Button in a widget, but so far I have not had success. Is this currently possible with AppIntentPackage or some other means? Is there a way I can use AppIntents to pass a message back to the app? How should I approach this?
Thank you!
Explore enhancements to App Intents
RSS for tagDiscuss the WWDC23 Session Explore enhancements to App Intents
Posts under wwdc2023-10103 tag
13 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi,
I am trying to integrate the new AppIntentsPackage protocol into my application. Especially what I want to do is to create a dedicate SPM package which holds all my app intents and then share that with my widget extension for Widget intents as well as the main iOS app for powering an AppShortcutProvider. Unfortunately I run into an issue here.
I have the following explanatory setup:
SPM package called ProjectAppIntents
iOS target
My AppIntents SPM package
//Package: ProjectAppIntents
public struct TestAppIntent: AppIntent {
public static var title: LocalizedStringResource = "TestAppIntent"
@Parameter(title: "Parameter1", optionsProvider: ParameterOptionProvider())
public var parameter: String
public init(parameter: String) {
self.parameter = parameter
}
public init() { }
public func perform() async throws -> some IntentResult & ReturnsValue {
.result(value: 5)
}
}
struct ParameterOptionProvider: DynamicOptionsProvider {
func results() async throws -> [String] {
return ["Hello", "World"]
}
}
public struct ProjectAppIntentsPackage: AppIntentsPackage { }
My iOS app
// Target: iOS
import ProjectAppIntents
struct ProjectApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
extension ProjectApp: AppIntentsPackage {
static var includedPackages: [AppIntentsPackage.Type] = [
ProjectAppIntentsPackage.self
]
}
struct ProjectShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: TestAppIntent(),
phrases: ["Start a \(.applicationName)"],
shortTitle: "Hello World",
systemImageName: "house"
)
}
}
When I now try to compile my app, I get the following build error:
2023-06-25 09:53:47.853 appintentsnltrainingprocessor[44848:2059163] Parsing options for appintentsnltrainingprocessor
2023-06-25 09:53:47.854 appintentsnltrainingprocessor[44848:2059163] Starting AppIntents SSU YAML Generation
2023-06-25 09:53:47.868 appintentsnltrainingprocessor[44848:2059163] error: The action TestAppIntent referenced in App Shortcut does not exist
Command AppIntentsSSUTraining failed with a nonzero exit code
So for me it seems like the compiler cannot find the AppIntent defined in an SPM package.
Am I doing something wrong here or does the AppIntentsPackage protocol not work with SPM packages ?
Thanks a lot for helping !
I have run the demo "Food Truck", which implement the AppShortcut. I found that the shortcuts need to be added to shortcut and can't to be search in the spotlight even I had make sure it is "suggest in search"
iOS 17.0 simulator
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.
AppIntent of the same type is created both for main and widget targets. If app is launched in background, built-in main target intent is executed, but if app is closed, then app is not launched in background mode to execute built-in intent.
Is it supposed to be like this or is it a bug?
Do watchOS Complications support interactivity via App Intents?
I see that the Button initializer IS supported on watchOS, but any widget I try this on only seems to open the watch app.
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!
I am trying to implement App Shortcuts for my app. I want to implement the same as Books. I am trying to do 2 things.
I want to set a custom image for each App Shortcut.
I want to set custom color for the Shortcuts background like orange in the Books App Shortcuts.
I am trying to implement in iOS 16.
Kindly share your ideas.
If at all possible, kindly share a snippet
I tried to add iOS 17 version check inside WidgetBundle but the widget extension keep on crashing .
Getting Thread 1: Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value. After removing the iOS 17 check it works fine.
Is there any way to provide version check inside widgetBundle?
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)
I have a SiriKit type in intent definition which include system field 'identifier' and a custom field id. When I try to migrate to AppIntent, since AppEntity conforms to 'Identifiable' I cannot use 'id' in AppEntity, how can I solve this?
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 …
Was watching this latest WWDC 2023 video and had a question. I see about 17:20 in, they mention you can now put the shortcut provider in an app intent extension.
https://developer.apple.com/videos/play/wwdc2023/10103/
This works fine by itself and I can see all my shortcuts and use siri, but as soon as I try to call into the extension from the main app in order to trigger updateAppShortcutParameters() or any other code, I get a linker error. Am I doing something obvious wrong? Note, I called it a framework, but it Is just an extension. Cant figure out how I am supposed to be calling this method.
Any help is greatly appreciated!
https://developer.apple.com/documentation/appintents/appshortcutsprovider/updateappshortcutparameters()?changes=_4_8
https://imgur.com/a/yDygSVJ