根据 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");
}
}];
}}