Section 12/181 menit
12. Apple Intelligence & Siri Integration (iOS 18+)
12. Apple Intelligence & Siri Integration (iOS 18+)
Di iOS 18, Apple Intelligence membuat Siri jauh lebih cerdas — ia bisa memahami request natural language yang kompleks dan memetakannya ke App Intents kamu secara otomatis.
Syarat untuk Apple Intelligence Integration
swift
// 1. Intent harus conform AppIntent (sudah)
// 2. Tambahkan assistantSchemas untuk memberikan semantic hints ke AI
@AssistantIntent(schema: .system.createReminder) // gunakan schema standar jika ada
struct CreateReminderIntent: AppIntent {
// ...
}
// Untuk custom domain, definisikan sendiri:
struct AddTaskIntent: AppIntent {
static var title: LocalizedStringResource = "Tambah Tugas"
// Metadata untuk Apple Intelligence
static var description = IntentDescription(
"Tambahkan tugas baru ke daftar tugas",
categoryName: "Manajemen Tugas",
searchKeywords: ["buat", "tambah", "tugas", "reminder", "todo"]
)
@Parameter(title: "Judul", requestValueDialog: "Apa judul tugasnya?")
var title: String
@Parameter(title: "Prioritas", default: .medium)
var priority: PriorityLevel
@Parameter(title: "Tenggat")
var dueDate: Date?
func perform() async throws -> some IntentResult & ProvidesDialog {
let task = try await TaskRepository.shared.create(
title: title, priority: priority, dueDate: dueDate
)
return .result(dialog: "Tugas '\(task.title)' sudah ditambahkan.")
}
}
Siri Natural Language → App Intent Mapping
Dengan Apple Intelligence, Siri bisa memahami frasa natural yang belum kamu daftarkan secara eksplisit:
swift
User: "Ingatkan aku besok untuk meeting dengan klien, prioritas tinggi"
↓
Apple Intelligence parse:
- intent: AddTaskIntent
- title: "Meeting dengan klien"
- dueDate: tomorrow
- priority: .high
Siri eksekusi: AddTaskIntent.perform()
AssistantSchemas: Semantic Compatibility
swift
// Gunakan schema standar Apple untuk interoperabilitas
// Schema standar memastikan intent bisa di-trigger dari berbagai konteks
// Untuk app catatan/tasks:
@AssistantIntent(schema: .system.createNote)
struct CreateNoteIntent: AppIntent {
@Parameter(title: "Judul") var title: String
@Parameter(title: "Konten") var body: String
func perform() async throws -> some IntentResult & ReturnsValue<NoteEntity> {
let note = try await NoteRepository.shared.create(title: title, body: body)
return .result(value: NoteEntity(note: note))
}
}
// Untuk app email/messaging:
@AssistantIntent(schema: .mail.createEmail)
struct ComposeEmailIntent: AppIntent {
@Parameter(title: "Penerima") var recipient: String
@Parameter(title: "Subjek") var subject: String
@Parameter(title: "Isi") var body: String
func perform() async throws -> some IntentResult {
try await EmailService.shared.compose(to: recipient, subject: subject, body: body)
return .result()
}
}