Update Siri intent handler response from the intent view controller

24 Views Asked by At

Currently, I am trying to update the response for my success message in on my siri intents through my intent view controller, however, when I say the command in siri, it only runs the default parameter passed in my intent handler and completely bypasses the value I initialized the response parameter in intent view controller.

class IntentViewController: UIViewController, INUIHostedViewControlling {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        FirebaseApp.configure()
    }
    
    func configureView(for parameters: Set<INParameter>, of interaction: INInteraction, interactiveBehavior: INUIInteractiveBehavior, context: INUIHostedViewContext, completion: @escaping (Bool, Set<INParameter>, CGSize) -> Void) {
        

        if interaction.intentHandlingStatus == .success {
            if let response = interaction.intentResponse as? ViewMyMedsIntentResponse {
                response.meds = ["tylenol", "advil", "morphine"]
                getMedsString { [weak self] medsArray in
                    guard let self = self else {
                        // Handle the case when self has been deallocated before the closure is executed
                        completion(false, parameters, self?.desiredSize ?? CGSize.zero)
                        return
                    }
                    
                    let medView = MedsView()
                    self.view.addSubview(medView)
                    medView.translatesAutoresizingMaskIntoConstraints = false
                    NSLayoutConstraint.activate([
                        medView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
                        self.view.trailingAnchor.constraint(equalTo: medView.trailingAnchor),
                        medView.topAnchor.constraint(equalTo: self.view.topAnchor),
                    ])
                    medView.setNeedsLayout()
                    medView.layoutIfNeeded()
                    medView.update(meds: medsArray)
                    completion(true, parameters, CGSize(width: self.desiredSize.width, height: medView.frame.height))
                }
                
                return
            }
            
        }
    }
}
import Foundation
import os.log
import Intents

public class ViewMyMedIntentHandler: NSObject, ViewMyMedsIntentHandling {
    
    public func handle(intent: ViewMyMedsIntent, completion: @escaping (ViewMyMedsIntentResponse) -> Void) {
        
        let response = ViewMyMedsIntentResponse(code: .success, userActivity: nil)   
        response.meds = ["None"]  
        completion(response)
    }
    
    
}

[This is what my intents definition looks like for ViewMyMedsIntent(https://i.stack.imgur.com/zETac.png)

So just to recap, in the intent view controller, I want siri to say aloud ["tylenol", "advil", "morphine"], but like I said, it bypasses this and just read the ["None"] that I passed in the intent handler as the default value.

I tried to update the response in intent view controller by doing response.meds hoping that it would update the response value and siri would read aloud all the meds, but instead it just reads whatever is passed in intent handler. Also just as a quick note, I dont want to do any updating in the intent handler, because my plan is to query a firebase database, which I can only access in the intent view handler due to i can only import the firebase database since the library is added in intent view controller.

0

There are 0 best solutions below