Sirikit, How to Display Response for Start Workout Intent

Siri always responds 'Continue in the app' when starting workout with SiriKit

Once you are ready to start the workout in your app, you need to call the completion handler with .continueInApp

So that would be something like:

public func handle(startWorkout intent: INStartWorkoutIntent, completion: @escaping (INStartWorkoutIntentResponse) -> Swift.Void) {
let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartWorkoutIntent.self))
let response = INStartWorkoutIntentResponse(code: .continueInApp, userActivity: userActivity)
completion(response)
}

See the documentation:

Your extension is ready to transfer control to the app so that the workout can be started. Upon returning this code, SiriKit launches your app and passes it the NSUserActivity object you provided at initialization time. (If you did not provide a user activity object, SiriKit creates one for you.) SiriKit adds an INInteraction object with the intent and your response to the user activity object before delivering it. Your app should use the information in the user activity object to start the workout.

Facing issue in Siri Integration with custom intents

Find my analysis for the above questions.

  1. Can we add the intents programmatically to Siri instead adding from shortcuts app or settings. So that user can directly use the functionality once installing the application.

By default, intents are provided for specific domains such as messaging, payments, photos, workout, etc. No need to explicitly add intents through shortcuts for theses specific domains. Apart from these domains if we are creating custom intent, we are in need to donate and add the intents to Siri using shortcut/settings application.


  1. Once intent is added using Shortcuts app, I’m trying the ask Siri for reward points. Its immediately requesting for my app shortcuts defined. Once we say 'yes' to request, I need to be asked for pin. But Siri replies with some problem with my app. What to be done for asking for next param value.

From iOS13, Apple has added Siri parameters and Siri suggestion for custom intents to request the missing parameters. Till iOS12, we don't have parameters option for custom intents.


  1. In the handler file, I have added the resolve methods for each parameters. I feel, resolve methods are not getting called to validate the values. Do we need to handle anything to make resolve methods work?

In iOS12, we cannot add resolve methods for parameters in custom intents. Resolve methods handled only for specific domains provided within Intents extensions as mentioned in question 1. From iOS13, we can have resolve methods for custom intents based on the parameters.


  1. How can I debug the handler implementation using breakpoint within resolve/handle/confirm methods.

We can add breakpoints and debug intent handler methods.

Thanks.

Widget SiriKit intent enum value for index

I ended up creating an Int enum containing the same as in my intentdefinition. Then created an extension for my enum to return a string value for the intent's rawValue. I was mistaken that my intentdefinition would provide me a string value for the index.

enum SortBy : Int {
case hot = 1
case new
case controversial
case top
case rising
}

extension SortBy {
var sortValue: String {
switch self {
case .hot:
return "hot"
case .new:
return "new"
case .controversial:
return "controversial"
case .top:
return "top"
case .rising:
return "rising"
}
}
}
SortBy(rawValue: configuration.sort.rawValue)!

SiriKit payment confirmation currency is always US$

You need to add a paymentRecord to your response in

(void)confirmSendPayment:(INSendPaymentIntent *)intent

like so:

INSendPaymentIntentResponse *response = [[INSendPaymentIntentResponse alloc] initWithCode:INSendPaymentIntentResponseCodeReady userActivity:userActivity];
response.paymentRecord = [[INPaymentRecord alloc] initWithPayee:intent.payee payer:nil currencyAmount:intent.currencyAmount paymentMethod:nil note:intent.note status:INPaymentStatusPending];
completion(response);


Related Topics



Leave a reply



Submit