Created
June 28, 2018 18:36
-
-
Save azamsharp/94c95b82a30e15dcc13bdec4cbb8d82f to your computer and use it in GitHub Desktop.
Siri Shortcuts Using UserActivity
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
// | |
// ViewController.swift | |
// NailasCoffee | |
// | |
// Created by Mohammad Azam on 6/28/18. | |
// Copyright © 2018 Mohammad Azam. All rights reserved. | |
// | |
import UIKit | |
import Intents | |
import CoreSpotlight | |
import CoreServices | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
@IBAction func orderCoffee() { | |
// code for ordering the coffee | |
// donate the user activity | |
} | |
private func donateActivity() { | |
let userActivity = NSUserActivity(activityType: " com.azamsharp.nailascoffee.ordercoffee") | |
userActivity.isEligibleForSearch = true | |
userActivity.isEligibleForPrediction = true | |
userActivity.title = "Activity" | |
userActivity.userInfo = ["key": "value"] | |
userActivity.suggestedInvocationPhrase = "Let's do it" | |
let attributes = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String) | |
let image = UIImage(named: "myImage")! | |
attributes.thumbnailData = image.pngData() | |
attributes.contentDescription = "Subtitle" | |
userActivity.contentAttributeSet = attributes | |
self.userActivity = userActivity | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment