Working with Text Input
Transcription
Working with Text Input
Working with Text Input The Apple Watch does not provide a keyboard for users to input text, however it does support some watch-friendly alternatives: Selecting from a pre-defined list of text options, Siri dictation, or Choosing an emoji. The simulator does not currently support either Siri dictation or emoji but you can still build and test the text input controller using a pre-defined list of options: Accepting text input in a watch app requires these steps: 1. Create a string array of predefined options. 2. Call PresentTextInputController with the array, whether to allow emoji or not, and an Action that is called when the user is finished. 3. In the completion action, test for the input result and take appropriate action in your app (possibly setting a label's text value). The following code snippet presents three pre-defined options to the user: var suggest = new string[] {"Get groceries", "Buy gas", "Post letter"}; PresentTextInputController (suggest, WatchKit.WKTextInputMode.AllowEmoji, (result) => { // action when the "text input" is complete if (result != null && result.Count > 0) { // this only works if result is a text response enteredText = result.GetItem<NSObject>(0).ToString(); Console.WriteLine (enteredText); // do something, such as myLabel.SetText(enteredText); } }); The WKTextInputMode enumeration has three values: Plain AllowEmoji AllowAnimatedEmoji In the current beta of Watch Kit it's not possible to see how the emoji selection works. If an emoji is selected the result in the completion handler will contain an NSData object that contains the emoji UIImage. Sample code for this will be available in a future preview release.