Skip to content

Instantly share code, notes, and snippets.

@russell-archer
Created October 8, 2018 23:39
Show Gist options
  • Save russell-archer/58d14ca3cf1a2a2de0ed85cdad58fc07 to your computer and use it in GitHub Desktop.
Save russell-archer/58d14ca3cf1a2a2de0ed85cdad58fc07 to your computer and use it in GitHub Desktop.
ShowRandomColor. The app extension code
//
// ColorIntentHandler.swift
// ColorIntent
//
// Created by Russell Archer on 06/10/2018.
// Copyright © 2018 Russell Archer. All rights reserved.
//
import Foundation
import ColorGenerator
class ColorIntentHandler: NSObject, ShowRandomColorIntentHandling {
func confirm(intent: ShowRandomColorIntent, completion: @escaping (ShowRandomColorIntentResponse) -> Swift.Void) {
completion(ShowRandomColorIntentResponse(code: .ready, userActivity: nil))
}
func handle(intent: ShowRandomColorIntent, completion: @escaping (ShowRandomColorIntentResponse) -> Void) {
let colorInfo = Generate.randomColor()
// Save the generated random color in our shared user default plist so the app extension UI can access it
let defaults = UserDefaults.init(suiteName: "group.com.rarcher.ShowRandomColor.Shared")
defaults!.set(colorInfo.name, forKey: "colorName")
// Tell Siri the shortcut was a success
completion(ShowRandomColorIntentResponse.success(colorName: colorInfo.name))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment