When using just the application name in a phrase, it works great and the shortcut can be invoked via Siri:
e.g. "Show books in \(.applicationName)" // This works
But introducing a parameter in a phrase fails to create a working shortcut that can be invoked via Siri:
e.g. "Show \(\.$book) in (\.applicationName)" // Does not work
where $book
is a parameter for BookEntity
in my intent.
i am calling updateAppShortcutParameters()
and i only have a single book titled "Frankenstein". When my App is launched after a fresh install, i can see that a shortcut is automatically created in the Shortcuts App but has the following title:
"Show %@ in MyAppName"
Even though the title looks incorrect, tapping the shortcut works and the correct book title is passed to my Intent. However, i cannot invoke the shortcut using Siri. i.e. saying "Show Frankenstein in MyAppName" does not work.
Has anyone run into this particular issue? i am running Xcode 14 Beta 6 and iOS 16 Beta 7 on my iPhone. Also tested in iOS Simulator and got the same results.
This is arguably the biggest selling point for App Shortcuts (zero setup required by the user) so i am hoping it is addressed before iOS 16 becomes officially available.
@denrase: i meant to post the solution here sooner, i finally got it to work late last night. Take a look at the code below. This appears to be an issue with LocalizedStringResource
and string interpolation (i think). When the DisplayRepresentation
sets the title to "\(title)"
, it causes the resulting shortcut to have a %@
in its title. Changing it to use a LocalizedStringResource
with a default value gets around the issue.
struct BookEntity: AppEntity {
static let defaultQuery = BookQuery()
static let typeDisplayRepresentation = TypeDisplayRepresentation(name: "Book")
let id: UUID
let title: String
var displayRepresentation: DisplayRepresentation {
// DisplayRepresentation(title: "\(title)") // This causes the %@ to appear in the shortcut title
DisplayRepresentation(title: LocalizedStringResource("%@", defaultValue: String.LocalizationValue(title))) // This works
}
}
i don't have a Localizable.strings
file in my project, so using just "\(title)"
should work. Will log a feedback on this issue.