Created
October 8, 2018 23:35
-
-
Save russell-archer/0a9e0ec4fdfe2d6d42a6e2e21e4f5e46 to your computer and use it in GitHub Desktop.
ShowRandomColor. Donate the Siri shortcut
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
// | |
// ViewController.swift | |
// ShowRandomColor | |
// | |
// Created by Russell Archer on 05/10/2018. | |
// Copyright © 2018 Russell Archer. All rights reserved. | |
// | |
import UIKit | |
import ColorGenerator | |
import Intents // Import the Intents module | |
class ViewController: UIViewController { | |
@IBOutlet weak var colorView: UIView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setColor() | |
} | |
func setColor() { | |
let colorInfo = Generate.randomColor() | |
colorView.backgroundColor = colorInfo.color | |
donateIntent() // Let iOS know the user performed a shortcut action | |
} | |
// Donate the shortcut to iOS so Siri can build a usage pattern | |
func donateIntent() { | |
let intent = ShowRandomColorIntent() | |
intent.suggestedInvocationPhrase = "Random color" | |
let interaction = INInteraction(intent: intent, response: nil) | |
interaction.donate { (error) in | |
if error != nil { | |
print("Intent donation failed") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment