有没有办法在Apple Watch上输入文字?

7
在我的 Apple Watch 应用程序中,我需要输入文本,那么有没有办法使用 VoiceOver 或其他方式在我的应用程序中输入文本?
因为我发现 WKInterfaceController 中的对象都不支持像 UITextfield 或 UITextview 一样的可编辑文本输入。
5个回答

8

上面的答案没有代码,只有一个链接到苹果惊人的XD文档。 您可以使用以下代码(WatchOS2,iOS 9.2.1)启动具有一些语音选项的语音识别菜单:

//LAUNCH VOICE DICTATION (physical device only)
    func launchVoiceDictationMenu(){
        self.presentTextInputControllerWithSuggestions(["Hello","Goodbye","Hey"], allowedInputMode: WKTextInputMode.Plain,
            completion:{(results) -> Void in
                let aResult = results?[0] as? String
                print(aResult)
        })
    }

5

使用Swift 3更新watchOS 3涂鸦模式

presentTextInputController(withSuggestions: ["watchOS3"], allowedInputMode:   WKTextInputMode.plain) { (arr: [Any]?) in
        print(arr ?? "Not find")
    }

4
随着watchOS 3的到来,新增了“手写”模式。
[self presentTextInputControllerWithSuggestions:@[@"watchOS3"]; allowedInputMode:WKTextInputModePlain completion:^(NSArray *array){

    if (array != nil) {

        for (int i=0; i<[array count]; i++) {

            NSString *str = [array objectAtIndex:0];

            NSLog(@"%@",str);
        }

    }

}];

enter image description here enter image description here


3
是的,你可以使用语音输入(手表有麦克风)或在屏幕上直接选择表情符号来在Apple Watch中输入文本。根据苹果文档所述:
WatchKit为从用户检索文本输入提供了标准的模态界面。当呈现时,该界面允许用户通过语音输入或从一组标准短语或表情符号中进行选择来输入文本。

谢谢Nikos,这很有帮助。如果可能的话,请分享代码示例。 - Abhishek Sinha
@AbhishekSinha 苹果文档的链接中也有关于文本输入的代码示例 :-) - Nikos M.
@AbhishekSinha 我写了一篇快速的博客文章,可能会对你有所帮助:http://www.fiveminutewatchkit.com/blog/2015/3/15/how-to-get-text-input-from-the-user - bgilham
使用WatchKit的文本输入漂亮教程:http://natashatherobot.com/watchkit-text-input-dictation-api/ - Nikos M.

3

Swift 4

@IBAction func ReplyWithTextInputController(){

    let phrases = ["OK", "I'm busy.", "Where are you?", "Thanks."]

    presentTextInputController(withSuggestions: phrases,
                                    allowedInputMode: WKTextInputMode.allowEmoji, completion: { (result) -> Void in

                                        guard let choice = result else {
                                            return
                                        }
                                        let suggestion = choice[0]
                                        print(suggestion)

                        })

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接