Using App Intents for Apple Intelligence in iOS 18
Apple Intelligence in iOS 18 transforms how users interact with apps, allowing Siri and system-level features to understand on-screen context, retrieve specific app content, and execute actions across applications. This article provides a technical overview of how developers can adopt the enhanced App Intents framework to expose their application’s data and functionality to Apple Intelligence. By defining structured models, adopting predefined system schemas, and indexing content, you can make your app's core capabilities discoverable and actionable by Apple’s foundation models.
Understanding the Role of App Intents in iOS 18
Apple Intelligence does not scrape app interfaces; instead, it relies on semantic metadata provided programmatically. The App Intents framework serves as the primary bridge between your app's logic and the system models. In iOS 18, this framework has been expanded to support deeper semantic understanding, enabling Apple Intelligence to reason about your app’s data, answer queries, and perform multi-step workflows on behalf of the user.
Exposing Data Using App Entities
To make your app's data visible to Apple Intelligence, you must model
that data using the AppEntity protocol. An entity
represents a concept or object within your domain—such as a project,
note, transaction, or photo.
import AppIntents
struct ProjectEntity: AppEntity {
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Project")
var id: UUID
var title: String
var dueDate: Date?
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: "\(title)")
}
static var defaultQuery = ProjectQuery()
}To allow Apple Intelligence to look up and resolve specific entities,
implement an EntityQuery or EntityStringQuery.
This enables Siri to locate entities based on criteria like titles, IDs,
or natural language search terms.
struct ProjectQuery: EntityStringQuery {
func entities(matching string: String) async throws -> [ProjectEntity] {
// Fetch and return matching projects from your data store
return Database.shared.searchProjects(query: string)
}
func entities(for identifiers: [UUID]) async throws -> [ProjectEntity] {
return Database.shared.getProjects(ids: identifiers)
}
}Adopting System App Intents
In iOS 18, Apple introduced specialized system schemas across various categories—including photography, document editing, messaging, and productivity. Instead of defining entirely custom intents, developers should adopt these pre-trained system schemas. When an intent conforms to a system-defined schema, Apple Intelligence already understands its context, expected parameters, and semantic outcome.
Examples of domain-specific system intents include:
- Create Intent: Allows Siri to generate a new item inside your app.
- Open Intent: Directs the system to navigate directly to an entity.
- Set/Update Intent: Enables updating specific attributes of an entity.
import AppIntents
struct OpenProjectIntent: OpenIntent {
static var title: LocalizedStringResource = "Open Project"
@Parameter(title: "Project")
var target: ProjectEntity
func perform() async throws -> some IntentResult {
NavigationRouter.shared.open(projectID: target.id)
return .result()
}
}Making App Content Searchable via Core Spotlight
For Apple Intelligence to reference your app's data when answering
general user prompts, that data must be indexed locally. iOS 18 deeply
integrates AppEntity with CoreSpotlight.
By conforming your entities to IndexedEntity, you allow
Apple Intelligence to semantically parse the entity’s attributes in
Spotlight:
extension ProjectEntity: IndexedEntity {
var attributeSet: CSSearchableItemAttributeSet {
let attributes = CSSearchableItemAttributeSet(contentType: .content)
attributes.title = title
attributes.contentDescription = "Due on \(dueDate?.formatted() ?? "No date")"
return attributes
}
}When data changes, update the spotlight index immediately:
import CoreSpotlight
CSSearchableIndex.default().indexAppEntities([projectEntity])Registering App Shortcuts
To make your intents immediately accessible without prior user
configuration, expose them via an AppShortcutsProvider.
This informs Apple Intelligence of the primary capabilities your app
supports as soon as the app is installed.
struct AppShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: OpenProjectIntent(),
phrases: [
"Open my \(\.$target) in \(.applicationName)",
"Show \(\.$target) using \(.applicationName)"
],
shortTitle: "Open Project",
systemImageName: "folder"
)
}
}Best Practices for Apple Intelligence Integration
- Provide Clear Parameter Summaries: Use expressive strings and descriptive parameter titles to help models resolve references accurately.
- Handle Entity Resolution Gracefully: If a query returns multiple matches or no matches, supply robust prompts or error handling so the system can ask the user clarifying questions.
- Keep Indexes Fresh: Continually sync entity updates and deletions with Spotlight to prevent Apple Intelligence from acting on outdated records.
- Respect Privacy and Permissions: Apple Intelligence processes data on-device and via Private Cloud Compute; ensure your intents do not expose sensitive user data beyond what is necessary to fulfill the request.