Created
October 8, 2018 23:39
-
-
Save russell-archer/58d14ca3cf1a2a2de0ed85cdad58fc07 to your computer and use it in GitHub Desktop.
ShowRandomColor. The app extension code
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
// | |
// 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