-
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.
Merge remote-tracking branch 'origin/trunk' into charlie/fix-intents-…
…version-number
- Loading branch information
Showing
6 changed files
with
184 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
39 changes: 39 additions & 0 deletions
39
IntentsExtension/IntentHandlers/CopyNoteContentIntentHandler.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,39 @@ | ||
// | ||
// CopyNoteContentIntentHandler.swift | ||
// IntentsExtension | ||
// | ||
// Created by Charlie Scheer on 5/29/24. | ||
// Copyright © 2024 Simperium. All rights reserved. | ||
// | ||
|
||
import Intents | ||
|
||
class CopyNoteContentIntentHandler: NSObject, CopyNoteContentIntentHandling { | ||
let coreDataWrapper = ExtensionCoreDataWrapper() | ||
|
||
func provideNoteOptionsCollection(for intent: CopyNoteContentIntent, 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: CopyNoteContentIntent, completion: @escaping (CopyNoteContentIntentResponse) -> Void) { | ||
guard let note = intent.note else { | ||
completion(CopyNoteContentIntentResponse(code: .unspecified, userActivity: nil)) | ||
return | ||
} | ||
|
||
guard let identifier = note.identifier, | ||
let content = coreDataWrapper.resultsController?.note(forSimperiumKey: identifier)?.content else { | ||
completion(CopyNoteContentIntentResponse(code: .failure, userActivity: nil)) | ||
return | ||
} | ||
|
||
let response = CopyNoteContentIntentResponse(code: .success, userActivity: nil) | ||
response.noteContent = content | ||
completion(response) | ||
} | ||
} |
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
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