Created
October 8, 2018 00:12
-
-
Save shiningabdul/f66347c8480d50d556853cdf39638f91 to your computer and use it in GitHub Desktop.
Starting intent manager
This file contains hidden or 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
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