-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dbd58b
commit 8a64a1e
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
IntentsExtension/IntentHandlers/FindNoteIntentHandler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// FindNoteIntentHandler.swift | ||
// IntentsExtension | ||
// | ||
// Created by Charlie Scheer on 5/29/24. | ||
// Copyright © 2024 Simperium. All rights reserved. | ||
// | ||
|
||
import Intents | ||
|
||
class FindNoteIntentHandler: NSObject, FindNoteIntentHandling { | ||
let coreDataWrapper = ExtensionCoreDataWrapper() | ||
|
||
func resolveNote(for intent: FindNoteIntent, with completion: @escaping (IntentNoteResolutionResult) -> Void) { | ||
// If the user has already selected a note return that note with success | ||
if let selectedNote = intent.note { | ||
completion(IntentNoteResolutionResult.success(with: selectedNote)) | ||
return | ||
} | ||
|
||
guard let content = intent.content else { | ||
completion(IntentNoteResolutionResult.needsValue()) | ||
return | ||
} | ||
|
||
completion(IntentNoteResolutionResult.resolveIntentNote(for: content, in: coreDataWrapper)) | ||
} | ||
|
||
func provideNoteOptionsCollection(for intent: FindNoteIntent, with completion: @escaping (INObjectCollection<IntentNote>?, (any Error)?) -> Void) { | ||
do { | ||
let intentNotes = try IntentNote.allNotes(in: coreDataWrapper) | ||
completion(INObjectCollection(items: intentNotes), nil) | ||
} catch { | ||
completion(nil, IntentsError.couldNotFetchNotes) | ||
} | ||
} | ||
|
||
func handle(intent: FindNoteIntent, completion: @escaping (FindNoteIntentResponse) -> Void) { | ||
guard let intentNote = intent.note else { | ||
completion(FindNoteIntentResponse(code: .failure, userActivity: nil)) | ||
return | ||
} | ||
|
||
let success = FindNoteIntentResponse(code: .success, userActivity: nil) | ||
success.note = intentNote | ||
|
||
completion(success) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters