/api-ai-cocoa-swift

Cocoa Swift library

Primary LanguageSwiftApache License 2.0Apache-2.0

DEPRECATED Cocoa SDK for api.ai

This library is deprecated. Please use API.AI's Apple Client library

Build Status Version License Platform Carthage Compatible


Overview

The API.AI iOS SDK makes it easy to integrate natural language processing API on Apple devices. API.AI allows using voice commands and integration with dialog scenarios defined for a particular agent in API.AI.

Prerequsites

Running the Demo app (CocoaPods supports only)

  • Run pod update in the AIDemo project folder.

  • Open AIDemo.xworkspace in Xcode.

  • In AppDelegate insert API key.

    AI.configure("YOUR_CLIENT_ACCESS_TOKEN")
    

    Note: an agent in api.ai should exist. Keys could be obtained on the agent's settings page.

  • Define sample intents in the agent.

  • Run the app in Xcode. Inputs are possible with text and voice (experimental).

Integrating into your app

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. Installing:

$ [sudo] gem install cocoapods

List "AI" in a text file named Podfile in your Xcode project directory:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'AI', '~> 0.7'
end

Now you can install the dependencies in your project:

$ pod install

Carthage

Carthage is intended to be the simplest way to add frameworks to your Cocoa application.

You can use Homebrew and install the carthage tool on your system simply by running brew update and brew install carthage.

Create a Cartfile with following text:

github "api-ai/AI"

Run carthage update. Drag the built AI.framework into your Xcode project.

Init the SDK.

In the AppDelegate.swift, add AI import:

import AI

In the AppDelegate.swift, add

// Define API.AI configuration here.
AI.configure("YOUR_CLIENT_ACCESS_TOKEN")

Perform request.

...
// Request using text (assumes that speech recognition / ASR
// is done using a third-party library, e.g. AT&T)
AI.sharedService.TextRequest("Hello").success { (response) -> Void in
    // Handle success ...
}.failure { (error) -> Void in
    // Handle error ...
}