Skip to content

Instantly share code, notes, and snippets.

@shiningabdul
Created October 8, 2018 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiningabdul/f66347c8480d50d556853cdf39638f91 to your computer and use it in GitHub Desktop.
Save shiningabdul/f66347c8480d50d556853cdf39638f91 to your computer and use it in GitHub Desktop.
Starting intent manager
import Foundation
import Intents
class IntentManager {
static let shared = IntentManager()
func intent(withMessage message:String) -> ShowMessageIntent {
let intent = ShowMessageIntent()
intent.message = message
return intent
}
func donateShortcuts(withIntent intent:INIntent) {
var relevantShortcuts:[INRelevantShortcut] = []
if let relevantShortcut = defaultRelevantShortcut(withIntent: intent) {
relevantShortcuts.append(relevantShortcut)
}
INRelevantShortcutStore.default.setRelevantShortcuts(relevantShortcuts) { (error) in
if let error = error {
print("Failed to set relevant shortcuts: \(error))")
} else {
print("Relevant shortcuts set.")
}
}
}
private func defaultRelevantShortcut(withIntent intent: INIntent) -> INRelevantShortcut? {
if let shortcut = INShortcut(intent: intent) {
let relevantShortcut = INRelevantShortcut(shortcut: shortcut)
relevantShortcut.shortcutRole = .information
return relevantShortcut
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment