0

I'm using the following to send text to wit.ai through a button press function:

@IBAction func searchButton(sender: AnyObject) {

    searchQueryText = searchTextInput.text!
    if searchQueryText != "" {
        wit.interpretString(searchQueryText, customData: nil)
    }

func interpretString(string: String, customData: AnyObject) {
}

this works fine as the text is sent to wit.ai. However I get no response from wit.ai back to the app. I can get the response fine if a microphone is used, just not text. I have tried calling the witDidGraspIntent function to force it to run on button press, but I can't work out what I should use in the 'outcomes' parameter. Can anybody help on this? I'm not sure if there is a different way to run the function after button press? This is the function:

func witDidGraspIntent(outcomes: [AnyObject]!, messageId: String!, customData: AnyObject!, error e: NSError!) {
    if ((e) != nil) {
        print("\(e.localizedDescription)")
        return
    }

    let outcomes : NSArray = outcomes!
    let firstOutcome : NSDictionary = outcomes.objectAtIndex(0) as! NSDictionary
    if let intent = firstOutcome.objectForKey("intent") as? String {
        searchResultsIntent = intent
    }

    if searchResultsIntent == "searchIntent" {

        intentLabel.text = "\(searchResultsIntent)"
        print(outcomes[0])

    } else {

        intentLabel.text = "I'm sorry, I did not understand that."
    }
}

here is the documentation for wit.ai: https://wit.ai/docs/ios/4.0.0/api

any assistance is greatly appreciated!

cheers.

mattblack
  • 1,370
  • 3
  • 13
  • 19

1 Answers1

0

Wit sdk gives a sharedInstance (singleton) for users to work on, so you have initiate it like -:

Wit.sharedInstance().accessToken = "TOKEN"
Wit.sharedInstance().delegate = self

and invoke the interpretString function using the sharedInstance i.e.

 Wit.sharedInstance().interpretString(text, customData: nil)
Hardik Shah
  • 916
  • 1
  • 7
  • 13