ApiAIWatchKit 0.0.2

ApiAIWatchKit 0.0.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年4月

Dmitriy Kuragin 维护。



  • Dmitriy Kuragin

为 Api.ai 提供的 Apple Watch 辅助库。

将库集成到您的应用中

1. 查看 Api.ai iOS SDK 参考以获取 Api.ai 初始化信息。

2. 在 AppDelegate.m 中添加

...
#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. 按照以下方式配置您的 Podfile

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

4. 在 WatchKit 扩展目标的 InterfaceController 中添加以下代码的 IBAction

...
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
                                             }];
                                         }
                                     }];
...