Last active
July 9, 2018 11:45
-
-
Save PattoMotto/ade3ff8ec7b175e40cd502522c3530d7 to your computer and use it in GitHub Desktop.
Method for present VoiceShortcutViewController and update UI, full project https://github.com/neungnarakjung/CookBook-Siri-Shortcuts-Example
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 UIKit | |
import IntentsUI | |
class ViewController: UIViewController { | |
private var shortcutManager: VoiceShortcutManager? | |
private var dataManager: CookBookDataManager? | |
private func presentVoiceShortcutViewController() { | |
guard let shortcutManager = shortcutManager, | |
let recipe = dataManager?.getRecipe("foo") else {return} | |
let cookBookIntent = CookBookIntent() | |
cookBookIntent.recipe = INObject(identifier: recipe.identifier, display: recipe.name) | |
guard let shortcut = INShortcut(intent:cookBookIntent) else {return} | |
if let voiceShortcuts = shortcutManager.voiceShortcuts, | |
let shortcut = voiceShortcuts.first { | |
let editSiriShortcutVC = INUIEditVoiceShortcutViewController(voiceShortcut: shortcut) | |
editSiriShortcutVC.delegate = self | |
present(editSiriShortcutVC, animated: true, completion: nil) | |
} else { | |
let addSiriShortcutVC = INUIAddVoiceShortcutViewController(shortcut: shortcut) | |
addSiriShortcutVC.delegate = self | |
present(addSiriShortcutVC, animated: true, completion: nil) | |
} | |
} | |
fileprivate func updateVoiceShortcuts() { | |
shortcutManager?.updateShortcut{ [weak self] in | |
self?.updateAddEditButton() | |
} | |
} | |
private func updateAddEditButton() { | |
DispatchQueue.main.async { [weak self] in | |
guard let strongSelf = self else {return} | |
if let voiceShortcuts = strongSelf.shortcutManager?.voiceShortcuts, | |
voiceShortcuts.first != nil { | |
strongSelf.updateTitleForEdit() | |
} else { | |
strongSelf.updateTitleForAdd() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment