Instruction
In iOS 18, Siri got a massive boost in capability. Siri now uses the App Intents framework alongside other system features such as Shortcuts and Search. In addition, Siri now has access to some APIs that use the Apple Intelligence framework introduced in iOS 18. Luckily, it doesn’t take much to integrate your existing app into both of those features.
Adding App Data to Spotlight
You can prepare your app for Siri by taking advantage of code you may already have in place or by adding code that is easy to implement if you haven’t.
First, adding entities from your app to Spotlight will let other system experiences that use App Intents use that information. The last lesson already had this since the AppEntity struct adopted IndexedEntity, and this code was added to the AppMain file.
Task {
try await CSSearchableIndex
.default()
.indexAppEntities(sessionDataManager.sessions.map(SessionEntity.init(session:)))
}
This allowed Spotlight to index information from your entities, which, among other things, made it searchable, as was shown in the demo in the last lesson.
Registering Shortcuts
You can easily implement the intents in your app as Shortcuts that can be used outside your app. For example, you can define a shortcut for an OpenFavorites intent like this:
class SessionShortcuts: AppShortcutsProvider {
static var shortcutTileColor = ShortcutTileColor.navy
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: OpenFavorites(),
phrases: [
"Open Favorites in \(.applicationName)",
"Show my favorite \(.applicationName)"
],
shortTitle: "Open Favorites",
systemImageName: "star.circle"
)
}
The AppShortcut here contains:
- An
intentto perform when the shortcut is run. - Phrases that are used when this shortcut is used with Siri. They must contain the name of the app.
- A short title to display for the shortcut when shown in the user interface, such as in the search results.
- An image name to display for the shortcut when shown in the user interface.
The array of AppShortcuts is registered with the system at install time, so the shortcuts are available even if the user hasn’t opened your app.
You need to register these shortcuts with the system, and you can easily do that by adding the following code to your main app file:
SessionShortcuts.updateAppShortcutParameters()
The updateAppShortcutParameters method is part of the AppShortcutsProvider protocol.
With shortcuts for your app defined and registered with the system, Siri now has access to those shortcuts, with no other work from you. The phrases provided in the AppShortcut allow the system to match your spoken phrase with the registered shortcut and run the intent.
Note: As of the release of this lesson, the use of parameters in the Siri phrases does not work. Siri will prompt the user for the correct parameter if your intent requires a parameter. See the demo for an example of this in action.
Using App Intent Domains
With Siri now able to access the App Intents framework, any intents currently in your app and those you develop in the future can respond to a user’s voice. But what about hooking them into Apple Intelligence?
Apple introduced the Assistant Schemas API to help interface your entities and intents with Apple Intelligence, using Swift Macros, a relatively recent addition to Swift. Apple has defined a series of domains with schemas for performing common tasks on the device. The Photos and Mail App Intent domains were made available early in the iOS 18 beta, and ten more domains were expected to be released during future update cycles, but Apple shifted their plans for Siri and App Intents to future releases of iOS . So why are these schemas so special?
Apple has already spent much time training its foundational learning models in iOS. This means you don’t have to spend time training the system to understand your intent. If your intent conforms to the schema, Apple Intelligence can reason over that intent when the user makes a request.
Note:
App Intent Domains are still in an uncertain state, even in iOS 26. Apple’s backtracking for their original plans for Siri and Apple Intelligence has shifted the schedule for their release to an indeterminate “future release”. You can still get ready for that future release now, though!
Adding an assistant schema to your existing code is easy. For example, say you have an intent to make a new photo folder:
import AppIntents
struct CreateFolder: AppIntent {
static let title = LocalizedStringResource("Create")
static let description = "Creates a folder"
@Parameter(title: "Folder name")
var name: String
func perform() async throws -> some ReturnValue<FolderEntity> {
return .result(value: FolderEntity(name: name))
}
}
You can easily make it adopt the Assistant Schema API with the simple addition of a macro:
import AppIntents
@AppIntent(schema: .photos.createAlbum)
struct CreateFolder: AppIntent {
var name: String
func perform() async throws -> some ReturnValue<FolderEntity> {
return .result(value: FolderEntity(name: name))
}
}
There are some changes here:
- The
@AppIntentmacro defines the domain and schema,.photos.createAlbum. Since the system knows the schema’s “shape,” there is no need to decorate the name property with a@Parameterso that it can be removed. - The title and description properties can also be removed.
Although not shown here, you can also add custom parameters to provide some flexibility. In other words, the schema shapes aren’t rigid but are instead slightly flexible. You still need certain conformance, like with a protocol, but you can add custom parameters for your specific intent. These parameters can be used in the perform action, which is always customized to meet your needs.
Putting It All Together
The “thin” Siri layer discussed in the last lesson is on display in this lesson. Besides automatically getting support for shortcuts, the Assistant Schemas API is a quick and easy way to add Apple Intelligence support to your existing entities, intents and enums, even reducing the required code in some instances. In the next segment, a demo will put all this into practice.