Use Siri Shortcuts to your favourite apps

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)

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

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

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
}
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
}
}

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

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.

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

 iOS Developer @nfnlabs, Chennai. Here to share best practices learned through my experience. Reach me on https://www.linkedin.com/in/ashokkumar-b-26026913a/

 iOS Developer @nfnlabs, Chennai. Here to share best practices learned through my experience. Reach me on https://www.linkedin.com/in/ashokkumar-b-26026913a/