ApiAIWatchKit 0.0.2

ApiAIWatchKit 0.0.2

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Apr 2015

Maintained by Dmitriy Kuragin.



  • By
  • Dmitriy Kuragin

Apple Watch helper library for Api.ai.

Integrating into your app

1. See Api.ai iOS SDK Reference for Api.ai initialization.

2. In the AppDelegate.m, add

...
#import <ApiAIWatchKit/AIWatchKitHandler.h>
...
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply
{
    if (![AIWatchKitHandler handleWatchKitRequest:userInfo andReply:reply]) {
        // you code for handle messages from watch
    }
}
...

3. Configure you Podfile like this:

...
# Pod for Apple Watch Extension target
pod 'ApiAIWatchKit/WatchKitForWatch'
...
# Pod for Phone application
pod 'ApiAIWatchKit/WatchKitForPhone'
...

4. In the InterfaceController of WatchKit Extension target add IBAction with following code:

...
NSArray *suggestions = @[
                         ...
                         // you suggestions for text input
                         ...
                         ];

[self presentTextInputControllerWithSuggestions:suggestions
                               allowedInputMode:WKTextInputModePlain
                                     completion:^(NSArray *results) {
                                         if (results.count) {
                                             AIWatchKitTextRequest *textRequest = [[AIWatchKitTextRequest alloc] init];

                                             textRequest.query = @[results.firstObject];

                                             [textRequest runWithCompletionWithSuccesfull:^(id response) {
                                                 NSString *text = response[@"result"][@"speech"];

                                                 // you handle response code
                                             } andFailure:^(NSError *error) {
                                                 // you handle error code
                                             }];
                                         }
                                     }];
...