Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make our Siri better by Mohit Anand

Make our Siri better by Mohit Anand

Swift Bangalore Chapter #18

Swift India

October 19, 2019
Tweet

More Decks by Swift India

Other Decks in Programming

Transcript

  1. TimeLine Pre iOS12 Limited Domains with Limited Intents
 (Making payments,

    working with notes, helping with your workouts )
  2. iOS 12 Siri Shortcuts
 Create custom intent to represent any

    domain
 Limitation: No multi step actions
  3. iOS 13 & above Conversational Siri Shortcuts
 Create custom intents

    with multi step actions. Siri can now ask follow-up questions.
  4. Demo App We will add this in-app top up feature

    to Siri knowledge system Top up Feature • List of Funds • Amount to top up for a fund • Success screen
  5. • Add your shortcut to Siri knowledge system by donating

    a NSUserActivity object every time user performs an action for which you want to create a shortcut. • Make your NSUserActivity, eligible for Siri Shortcut by a simple flag introduced in iOS 12.0. This will tell Siri that it can suggest this user activity as a shortcut to user.
  6. • Once your NSUserActivity is donated to system, it will

    be visible in Gallery section of Siri shortcuts app.
  7. • We can also Suggest a phrase which you want

    user to use for your shortcut by instance property introduced in iOS 12.0
  8. • Handle NSUserActivity in your App Delegate This will make

    sure, user activity directly goes to our topup page where user can select a fund to top up.
  9. Top up Shortcut via NSUserActivity • User says the selected

    phrase • Siri identifies it, and opens the appropriate application with the the same NSUSerActivity attached to the intent.
  10. • With custom intents, we can execute our feature directly

    in Siri, without opening the app. • For creating custom intent, we need to create an Intent Definition file • Intent Definition file is where all custom intents are defined.
  11. Choose the best category that describes your intent. For our

    use case, we will set our category as ORDER
  12. By Selecting the confirmation checkbox, siri ask user for the

    confirmation before completing the action. It is by default checked for some destructive or payment categories.
  13. Parameters for Topup • Fund - Which fund to top

    up? • Amount - What amount user want to top up?
  14. Xcode automatically creates intent object & it’s handling protocol when

    we define a custom intent in intent.definition file. Output of Intent Definition File
  15. Handling Intent • To handle any custom intent, we need

    to implement the respective handling protocol. • Provide data for parameters whose options are dynamic • Resolve parameters (Getting value for parameters) • Once the parameters are resolved or once we have all the values, we need to handle or complete the intent. • What does handling protocol consists? What are the things that we need to implement?
  16. • needsValue - if the value is nil and it

    is required, tell siri that you need value from user • confirmationRequired - siri will ask user for the confirmation of the parameter value • notRequired - value for parameter is not required, move on to the next parameter • success - valid value, move on to next parameter • unsupported - if the value is not supported, tell siri to ask question again • disambiguation - Siri will ask user to choose from the list of values provided with disambiguation. With this, you can provide or change the datasource.
  17. 4. Returns Valid Options 7. Converts the said or selected

    value to the expected parameter Lifecycle of Parameter Resolution Resolve Parmeter A SiriKit 1. Calls resolve initially 2. If value nil call needsValue() 5. Will ask user for the value. Provide Options A 3. For dynamic options 6. Selects or Says the value 8. Checks for the updated value in intent, return appropriate parameter resolution type Resolve Parmeter B 9c. Success or notRequired 9a. Unsupported or Disambiguation Resolution Type 9b. confirmationRequired 9b. If user confirmed
  18. Parameters are resolved when we return success or notRequired. Any

    other resolution result, will interact with the user again to get the value.
  19. Provide Handler • Now we need to provide our handler

    to sirikit. • Create Intent Extension target • Xcode creates a IntentHandler.swift file inside intent extension target for us when the target is created • Intent Handler file is where all intents are handled.
  20. Intent Handler The object we return in handler function must

    confirm to the protocol created for that intent.
  21. To enhance the user experience. We can actually show our

    custom UI according to the response code we return. • To show our custom UI, we need to create a new target - IntentUIExtension • Xcode automatically generates a view controller class (IntentViewController.swift), where we can add our own child view controller or simply a view. • We can provide different UI for different response codes