Skip to content

App Intents ile iOS Uygulamanızı AI-Ready Yapın: Siri ve Apple Intelligence Entegrasyonu

6 min read1,063 views
App Intents ile iOS Uygulamanızı AI-Ready Yapın: Siri ve Apple Intelligence Entegrasyonu
Contents
  1. Yeni Etkileşim Modeli
  2. İlk App Intent'iniz
  3. App Intent Anatomisi
  4. App Entity: Dinamik Veri Türleri
  5. App Enum: Sabit Değer Kümeleri
  6. App Shortcuts: Intent'leri Keşfedilebilir Yapın
  7. Assistant Schemas: Siri ile Derin Entegrasyon
  8. Pratik Örnek: To-Do Uygulaması
  9. Intent'leri Uygulamaya Kaydetme
  10. Hata Yönetimi
  11. Test Etme
  12. Checklist: Uygulamanızı AI-Ready Yapın
  13. Sonuç

Apple Intelligence ile iOS, kullanıcı arayüzünden kullanıcı niyetine geçiş yapıyor. Artık kullanıcılar buton tıklamak yerine "Siri, yarın için toplantı oluştur" diyerek uygulamanızı kontrol edebilir.

Bu geçişin anahtarı: App Intents Framework.

App Intents'i implement etmeyen uygulamalar AI-first bir işletim sisteminde görünmez kalacak. Bu rehberde, uygulamanızı Siri ve Apple Intelligence ekosistemine nasıl entegre edeceğinizi pratik Swift örnekleriyle gösteriyorum.

Yeni Etkileşim Modeli

Eski model:

Kullanıcı tıklar → Uygulama yanıt verir

Yeni model:

Kullanıcı niyet belirtir → Sistem yorumlar → Uygulama çalıştırır

Bu değişim sadece Siri için değil. App Intents şunlarla entegre:

  • Siri: Sesli komutlar
  • Spotlight: Arama sonuçları
  • Shortcuts: Otomasyon
  • Widgets: Etkileşimli widget'lar
  • Action Button: iPhone 15 Pro+ fiziksel buton
  • Apple Intelligence: AI destekli öneriler

İlk App Intent'iniz

En basit haliyle bir App Intent şöyle görünür:

import AppIntents

struct CreateTaskIntent: AppIntent {
    static var title: LocalizedStringResource = "Create Task"
    
    @Parameter(title: "Task name")
    var name: String
    
    func perform() async throws -> some IntentResult {
        TaskManager.shared.addTask(name)
        return .result(dialog: "Task created successfully")
    }
}

Bu kadar. Artık kullanıcı "Siri, create task called Buy groceries" diyebilir ve uygulamanız çalışır.

App Intent Anatomisi

Bir App Intent'in temel bileşenleri:

1. Title ve Description

struct SendMessageIntent: AppIntent {
    static var title: LocalizedStringResource = "Send Message"
    static var description = IntentDescription("Send a message to a contact")
}

2. Parameters

Kullanıcıdan alınacak değerler:

@Parameter(title: "Recipient")
var recipient: String

@Parameter(title: "Message content")
var content: String

@Parameter(title: "Priority", default: .normal)
var priority: MessagePriority

3. Perform Method

İşin yapıldığı yer:

func perform() async throws -> some IntentResult {
    let message = Message(to: recipient, content: content, priority: priority)
    try await MessageService.shared.send(message)
    return .result(dialog: "Message sent to \(recipient)")
}

App Entity: Dinamik Veri Türleri

Uygulamanızdaki nesneleri Siri'nin anlayacağı şekilde tanımlamak için App Entity kullanın:

struct TaskEntity: AppEntity {
    static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Task")
    
    var id: UUID
    var title: String
    var isCompleted: Bool
    
    var displayRepresentation: DisplayRepresentation {
        DisplayRepresentation(title: "\(title)")
    }
    
    static var defaultQuery = TaskQuery()
}

Entity Query

Sistem, entity'leri bulmak için query kullanır:

struct TaskQuery: EntityQuery {
    func entities(for identifiers: [UUID]) async throws -> [TaskEntity] {
        return TaskManager.shared.tasks
            .filter { identifiers.contains($0.id) }
            .map { TaskEntity(id: $0.id, title: $0.title, isCompleted: $0.isCompleted) }
    }
    
    func suggestedEntities() async throws -> [TaskEntity] {
        return TaskManager.shared.recentTasks
            .prefix(5)
            .map { TaskEntity(id: $0.id, title: $0.title, isCompleted: $0.isCompleted) }
    }
}

App Enum: Sabit Değer Kümeleri

Sabit seçenekler için App Enum:

enum TaskPriority: String, AppEnum {
    case low, normal, high, urgent
    
    static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Priority")
    
    static var caseDisplayRepresentations: [TaskPriority: DisplayRepresentation] = [
        .low: "Low",
        .normal: "Normal", 
        .high: "High",
        .urgent: "Urgent"
    ]
}

App Shortcuts: Intent'leri Keşfedilebilir Yapın

App Shortcuts, intent'lerinizi Spotlight ve Siri'de öne çıkarır:

struct TaskShortcuts: AppShortcutsProvider {
    static var appShortcuts: [AppShortcut] {
        AppShortcut(
            intent: CreateTaskIntent(),
            phrases: [
                "Create a task in \(.applicationName)",
                "Add task to \(.applicationName)",
                "New task in \(.applicationName)"
            ],
            shortTitle: "Create Task",
            systemImageName: "plus.circle"
        )
        
        AppShortcut(
            intent: CompleteTaskIntent(),
            phrases: [
                "Complete task in \(.applicationName)",
                "Mark task done in \(.applicationName)"
            ],
            shortTitle: "Complete Task",
            systemImageName: "checkmark.circle"
        )
    }
}

Assistant Schemas: Siri ile Derin Entegrasyon

Apple Intelligence ile çalışmak için Assistant Schemas kullanın. Bu, Siri'nin uygulamanızı anlamasını sağlar:

import AppIntents

@AssistantIntent(schema: .system.search)
struct SearchTasksIntent: AppIntent {
    static var title: LocalizedStringResource = "Search Tasks"
    
    @Parameter(title: "Query")
    var query: String
    
    func perform() async throws -> some IntentResult {
        let results = TaskManager.shared.search(query)
        return .result(value: results)
    }
}

Mevcut Schema Kategorileri

Apple, farklı uygulama türleri için hazır schema'lar sunuyor:

  • system.search: Uygulama içi arama
  • system.createNote: Not oluşturma
  • system.sendMessage: Mesaj gönderme
  • photos.openAsset: Fotoğraf açma
  • fitness.startWorkout: Egzersiz başlatma

Schema kullanmanın avantajı: Siri, uygulamanızın ne yaptığını daha iyi anlar ve doğal dil komutlarını daha iyi yorumlar.

Pratik Örnek: To-Do Uygulaması

Tam bir to-do uygulaması için intent seti:

// MARK: - Create Task
struct CreateTaskIntent: AppIntent {
    static var title: LocalizedStringResource = "Create Task"
    static var description = IntentDescription("Create a new task")
    
    @Parameter(title: "Title")
    var title: String
    
    @Parameter(title: "Due date", kind: .date)
    var dueDate: Date?
    
    @Parameter(title: "Priority")
    var priority: TaskPriority?
    
    static var parameterSummary: some ParameterSummary {
        Summary("Create task \(\.$title)") {
            \.$dueDate
            \.$priority
        }
    }
    
    func perform() async throws -> some IntentResult & ReturnsValue<TaskEntity> {
        let task = Task(
            title: title,
            dueDate: dueDate,
            priority: priority ?? .normal
        )
        
        let saved = try await TaskManager.shared.create(task)
        
        return .result(
            value: TaskEntity(from: saved),
            dialog: "Created task: \(title)"
        )
    }
}

// MARK: - Complete Task
struct CompleteTaskIntent: AppIntent {
    static var title: LocalizedStringResource = "Complete Task"
    
    @Parameter(title: "Task")
    var task: TaskEntity
    
    func perform() async throws -> some IntentResult {
        try await TaskManager.shared.complete(task.id)
        return .result(dialog: "Marked '\(task.title)' as complete")
    }
}

// MARK: - List Tasks
struct ListTasksIntent: AppIntent {
    static var title: LocalizedStringResource = "List Tasks"
    
    @Parameter(title: "Filter")
    var filter: TaskFilter?
    
    func perform() async throws -> some IntentResult & ReturnsValue<[TaskEntity]> {
        let tasks = TaskManager.shared.list(filter: filter ?? .all)
        let entities = tasks.map { TaskEntity(from: $0) }
        
        let count = entities.count
        let dialog = count == 0 
            ? "No tasks found" 
            : "You have \(count) task\(count == 1 ? "" : "s")"
        
        return .result(value: entities, dialog: dialog)
    }
}

Intent'leri Uygulamaya Kaydetme

App struct'ınızda intent'leri kaydedin:

@main
struct TaskApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
    
    init() {
        // App Shortcuts'u kaydet
        TaskShortcuts.updateAppShortcutParameters()
    }
}

Hata Yönetimi

Intent'lerde hata yönetimi için özel hata türleri:

enum TaskIntentError: Error, CustomLocalizedStringResourceConvertible {
    case taskNotFound
    case permissionDenied
    case networkError
    
    var localizedStringResource: LocalizedStringResource {
        switch self {
        case .taskNotFound:
            return "Task not found"
        case .permissionDenied:
            return "Permission denied"
        case .networkError:
            return "Network error. Please try again."
        }
    }
}

func perform() async throws -> some IntentResult {
    guard let task = TaskManager.shared.find(id: taskId) else {
        throw TaskIntentError.taskNotFound
    }
    // ...
}

Test Etme

Simulator'da Test

  1. Uygulamayı çalıştırın
  2. Shortcuts uygulamasını açın
  3. Intent'lerinizi bulun ve test edin

Siri ile Test

"Hey Siri, create task in [App Name]"
"Hey Siri, show my tasks in [App Name]"

Console Log

Debug için intent lifecycle'ını izleyin:

func perform() async throws -> some IntentResult {
    #if DEBUG
    print("🎯 Intent triggered: CreateTask")
    print("📝 Parameters: title=\(title), priority=\(priority ?? .normal)")
    #endif
    
    // ...
}

Checklist: Uygulamanızı AI-Ready Yapın

Uygulamanızı Apple Intelligence ekosistemine hazırlamak için:

  • Temel aksiyonları App Intent olarak tanımlayın
  • Önemli veri türlerini App Entity yapın
  • Sabit değerler için App Enum kullanın
  • App Shortcuts ile intent'leri keşfedilebilir yapın
  • Uygun Assistant Schema'ları uygulayın
  • Hata mesajlarını kullanıcı dostu yapın
  • Tüm intent'leri Shortcuts'ta test edin
  • Siri ile sesli komutları test edin

Sonuç

App Intents, iOS uygulamalarının geleceği. Apple Intelligence ile birlikte, kullanıcılar uygulamaları açmadan, sadece niyetlerini belirterek işlem yapabilecek.

Bu geçişe hazırlanmayan uygulamalar AI-first ekosistemde görünmez kalacak. Bugün başlayın:

  1. En çok kullanılan 3 aksiyonu belirleyin
  2. Bu aksiyonları App Intent olarak implement edin
  3. App Shortcuts ile keşfedilebilir yapın
  4. Test edin ve iterate edin

Kullanıcı deneyimi artık sadece UI değil. Kullanıcının niyetini anlayan ve ona göre hareket eden uygulamalar kazanacak.

Share this post