0

My requirement is basically to launch a specific screen in my app when a user says "Add a new diary entry".

Have done following configurations for it to work using NSUserAcitivity

  • Enabled the Siri in the capabilites
  • Added NSUserActivityTypes in the plist

Configured the useractivity as given below:

extension NSUserActivity {
  public static let openDiaryEntry = "XXX"
    public static var openDiaryAssetsActivity: NSUserActivity {
        let userActivity = NSUserActivity(activityType: NSUserActivity.openDiaryEntry)
        userActivity.title = "Add a new diary entry"
        userActivity.userInfo = ["viewControllerName": "DiaryEntryViewController"]
        userActivity.isEligibleForPrediction = true
        userActivity.isEligibleForSearch = true
        userActivity.persistentIdentifier = NSUserActivityPersistentIdentifier(NSUserActivity.openDiaryEntry)
        userActivity.suggestedInvocationPhrase = "Add a new diary entry"

        let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String)
        let image = UIImage(named: "AppIcon")!
        attributeSet.thumbnailData = image.pngData()
        attributeSet.contentDescription = "Tap to Add a new diary entry"
        userActivity.contentAttributeSet = attributeSet
        userActivity.becomeCurrent()
        return userActivity
    }
}

And assigned the activity in the ViewControllers viewDidLoad method as below:

   self.userActivity = NSUserActivity.openDiaryAssetsActivity

When I say "Hey Siri. Add a new diary entry", It opens the default calendar app IntentsUI to add an event. If I change the suggestedInvocationPhrase as "Add a new chai entry" it works properly by opening the app calling the respective scene delegate.

So, How can I override the specific keyword "Diary" to open my app instead of opening the default calendar app

niks
  • 544
  • 11
  • 28

0 Answers0