Use Siri Shortcuts to your favourite apps

Ashok
3 min readSep 19, 2018
Photo by Ash Edmonds on Unsplash

✅ Check whether you updated your mac and iPhone to the latest iOS 12 version

✅ Check whether you updated Xcode to Version 10.0

If you checked both , then simply follow the steps: 😄 👇

(here from my example, I created the shortcut for my existing demo app)

Step 1: Choose your app

(If your creating Siri Shortcuts for new app, skip now Step 1 & Step 2 but, should to do when push to AppStore)

Step 2: Enable SiriKit

Step 3: Enable Siri Capabilities

Step 4: Add NSSiriUsageDescription in info.list

<key>NSSiriUsageDescription</key>
<string>BUNDLE_IDENTIFIER.show</string>

Step 5: Add NSUserActivity Delegate

In AppDelegate, add NSUserActivity delegate. Inside this , call function (an action which you want to initiate while on doing Siri search)

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool 
{
let viewController = window?.rootViewController as! ViewController
viewController.showLabel()
return true
}

Step 6: Demo app UISetup

Step 7: Setup your NSUserActivity in IBAction

import UIKit
import Intents
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!override func viewDidLoad() {
super.viewDidLoad()
self.label.isHidden = true
}
@IBAction func press(_ sender: UIButton) {let activity = NSUserActivity(activityType: "BUNDLE_IDENTIFIER.show")
activity.title = "show"
activity.userInfo = ["color" : "red"]
activity.isEligibleForSearch = true
if #available(iOS 12.0, *) {
activity.isEligibleForPrediction = true
activity.persistentIdentifier = "BUNDLE_IDENTIFIER.show"
} else {
// Fallback on earlier versions
}
self.view.userActivity = activity
activity.becomeCurrent()
self.showLabel()
}
public func showLabel(){
self.label.isHidden = false
}
}

Step 8:

Run your project. Create the NSUserActivity by clicking the ‘press’.

Step 9:

Go back to the Settings -> Siri & Search -> SUGGESTED SHORTCUTS

Tap on ‘Show’ -> ‘ Add to Siri ’ screen will be displayed. Here you can record your personalised phrase.

Step 10:

Test your app, by doing Siri Search. Well, Here we are ! 🙌

--

--

Ashok

 iOS and Flutter developer @TCS, Chennai. Here to share best practices learned through my experience. Reach me on www.linkedin.com/in/ashok1208