SiriKit INSendMessageIntent skip confirm delegate

Home / Uncategorized / SiriKit INSendMessageIntent skip confirm delegate

Question:
I’ve been working on SiriKit for a while, and the result of my demo was not satisfied by my boss. By reading all the Apple documents & did my best to search online, I still can’t find a way to skip the confirm step in SendMessageIntent!

This is my purpose:
After resolving user comments to Siri,
func resolveContent(forSendMessage intent: INSendMessageIntent, with completion: @escaping (INStringResolutionResult) -> Void) {
if let text = intent.content, !text.isEmpty {
if text == "Login with Touch ID" {
completion(INStringResolutionResult.success(with: text))
} else if text == "Change password"{
completion(INStringResolutionResult.success(with: text))
}
completion(INStringResolutionResult.disambiguation(with: ["Login with Touch ID", "Change password"]))
} else {
completion(INStringResolutionResult.disambiguation(with: ["Login with Touch ID", "Change password"]))
}
}

Skip this step "confirm",
func confirm(sendMessage intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
// Verify user is authenticated and your app is ready to send a message.

let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
let response = INSendMessageIntentResponse(code: .success, userActivity: userActivity)

completion(response)
}

And do the handle delegate directly,
func handle(sendMessage intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
// Implement your application logic to send a message here.

let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
let response = INSendMessageIntentResponse(code: .success, userActivity: userActivity)

completion(response)
}

Hope there’s someone can answer this question for me. Thanks a lot!


Answer:
The confirm function is optional, you don’t need to implement it to be able to conform to the INSendMessageIntentHandling protocol, only the handle(intent:completion:) is required. This shows that you can skip the confirmation part.

You should just delete the confirm function and SiriKit will call your handle function directly, without the confirmation.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *