1

根据 Apple 的WKInterfaceController文档,您可以让用户以这种非常简单的方式来指示预设新界面控制器的文本:

self.presentTextInputControllerWithSuggestions(["suggestion 1", "suggestion 2"] allowedInputMode: .Plain, completion: { (answers) -> Void in
if reply && reply.count > 0 {
    if let answer = answers[0] as? String {
        println("\answer")
    }
}

})

如此所述。

我已经看到 Apple Watch 的 Amazon App 让您可以通过直接点击搜索图标来搜索产品

在此处输入图像描述

因此,您可以一步进入听写

在此处输入图像描述

通过WKInterfaceController方法,我们会得到不一样的东西

在此处输入图像描述

哪个 Apple 的 API Amazon 应用程序正在使用这种方式启用听写?

(更新)我刚刚发现它非常简单,如此处所述

所以我出来的最终解决方案是这个

    - (void) table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {
if (rowIndex==0) { // handle manual selection
    __weak MainInterfaceController *weakSelf = self;
    [self presentTextInputControllerWithSuggestions:nil allowedInputMode:WKTextInputModePlain completion:^(NSArray *results) {
       if(results && [results count]>0) {
           NSString *inputText=nil;
           for(NSString *input in results) {
               NSLog(@"Input %@", input);
               inputText=input;
               break;
           }
           if(inputText!=nil && [inputText length]>0) {
               [weakSelf pushControllerWithName:@"Search" context:
                [NSDictionary dictionaryWithObjectsAndKeys:
                 inputText, @"query", nil]
                ];
           }
       } else {
           NSLog(@"No input provided");
       }
   }];
}}
4

2 回答 2

2

将模式设置为.Plain,不提供任何建议。

于 2015-05-26T13:34:03.850 回答
1

如果您删除建议的字符串数组,它将直接进入听写模式。

于 2015-05-26T13:34:33.520 回答