Instruction

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In iOS 18, Siri is getting 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 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.

Task {
  try await CSSearchableIndex
    .default()
    .indexAppEntities(sessionDataManager.sessions.map(SessionEntity.init(session:)))
}

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"
    )
  }
SessionShortcuts.updateAppShortcutParameters()

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?

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))
  }
}
import AppIntents 

@AssistantIntent(schema: .photos.createAlbum)
struct CreateFolder: AppIntent {
  var name: String

  func perform() async throws -> some ReturnValue<FolderEntity> {
    return .result(value: FolderEntity(name: name))
  }
}

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.

See forum comments
Download course materials from Github
Previous: Introduction Next: Demo