Skip to content

Instantly share code, notes, and snippets.

@victorpanitz
Created October 25, 2019 19:25
Show Gist options
  • Save victorpanitz/d5abac88d1f8e2eaecda58d79bcb3bae to your computer and use it in GitHub Desktop.
Save victorpanitz/d5abac88d1f8e2eaecda58d79bcb3bae to your computer and use it in GitHub Desktop.
// Add an "Add to Siri" button to a view.
func addSiriButton(to view: UIView) {
let button = INUIAddVoiceShortcutButton(style: .blackOutline)
button.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
view.centerXAnchor.constraint(equalTo: button.centerXAnchor).isActive = true
view.centerYAnchor.constraint(equalTo: button.centerYAnchor).isActive = true
button.addTarget(self, action: #selector(addToSiri(_:)), for: .touchUpInside)
}
// Present the Add Shortcut view controller after the
// user taps the "Add to Siri" button.
@objc
func addToSiri(_ sender: Any) {
if let shortcut = INShortcut(intent: orderSoupOfTheDayIntent) {
let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut)
viewController.modalPresentationStyle = .formSheet
viewController.delegate = self // Object conforming to `INUIAddVoiceShortcutViewControllerDelegate`.
present(viewController, animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment