Use specific TouchScreenKeyboardType for different text fields

I have 2 text fields for input on an iOS app, one for name and one for email. I want to use TouchScreenKeyboardType.NamePhonePad and TouchScreenKeyboardType.EmailAddress for the corresponding fields. I have seen the docs at [TouchScreenKeyboard.Open][1]

[1]: Unity - Scripting API: TouchScreenKeyboard.Open , but don’t understand how I would apply that sample to text fields in C# such as:

public string nameText;
public string emailText;
    
// make name text field
nameText = GUI.TextField(new Rect(200, 300, 400, 55), nameText, 60, nameGS);
        		
// make email field
emailText = GUI.TextField(new Rect(200, 375, 400, 55), emailText, 80, nameGS);

I’m sure many people have done this but I can’t seem to put it together. Thanks for any help

Try this

public string nameText;
public string emailText;
TouchScreenKeyboard keyboardName;
TouchScreenKeyboard keyboardEmail;

// make name text field
keyboardName = TouchScreenKeyboard.Open(nameText, TouchScreenKeyboardType.Default);
nameText = GUI.TextField(new Rect(200, 300, 400, 55), nameText, 60, nameGS);

// make email field
keyboardEmail = TouchScreenKeyboard.Open(emailText, TouchScreenKeyboardType.EmailAddress); 
emailText = GUI.TextField(new Rect(200, 375, 400, 55), emailText, 80, nameGS);

In case anyone else is dealing with this, I ended up writing my own plugin to create native iOS textfields and textViews. It was a little tricky but not too bad. Writing a plugin basically involves creating a class in xcode, making some class methods that do what you need and then creating C methods that call the Obj-C class methods, then calling the C method in a Unity class using the method Unity shows in their docs. Building iOS Plugins

I started out by extending a plugin that I purchased and then just took what I learned from that and made my own. Here’s a snippet:

+ (void)createNameTextField:(CGFloat*)xValue yValue:(CGFloat*)yValue width:(CGFloat*)width height:(CGFloat*)height placeholder:(NSString*)placeholder returnKey:(NSString*)returnKey autoCorr:(NSString*)autoCorr font:(NSString*)font fontSize:(CGFloat*)fontSize
{
    CGRect frame = CGRectMake(*xValue, *yValue, *width, *height);
    
    nameField = [[UITextField alloc] initWithFrame:frame];
    nameField.keyboardType = UIKeyboardTypeNamePhonePad;
    nameField.placeholder = placeholder;
    [nameField setFont:[UIFont fontWithName:font size:*fontSize]];
    
    nameField.delegate = self;
    nameField.tag = 1;
    
    
    // setting return key type
    if ([returnKey isEqualToString:@"default"]) {
        nameField.returnKeyType = UIReturnKeyDefault;
    }
    
    else if ([returnKey isEqualToString:@"next"]) {
        nameField.returnKeyType = UIReturnKeyNext;
    }
    
    else if ([returnKey isEqualToString:@"done"]) {
        nameField.returnKeyType = UIReturnKeyDone;
    }
    else {
        NSLog(@"Error: choose a valid return key option (default, next, or done)");
    }
    
    // setting auto correct type
    if ([autoCorr isEqualToString:@"yes"]) {
        nameField.autocorrectionType = UITextAutocorrectionTypeYes;
    }

    else if ([autoCorr isEqualToString:@"no"]){
        nameField.autocorrectionType = UITextAutocorrectionTypeNo;
    }
    else if ([autoCorr isEqualToString:@"default"]){
        nameField.autocorrectionType = UITextAutocorrectionTypeDefault;
    }
    else {
        NSLog(@"Error: choose a valid autocorrection option (yes, no, or default)");
    }
    
    NSLog(@"returnKey: %@", returnKey);
    NSLog(@"autoCorr: %@", autoCorr);
    
    [UnityGetGLViewController().view addSubview:nameField];
    
}

Then the C method

`extern “C” {

void _catchfireCreateNameTextField( float xValue, float yValue, float width, float height, const char * placeholder, const char * returnKey, const char * autoCorr, const char * font, float fontSize)
{
  //  [[EtceteraManager sharedManager] createNameTextField:GetStringParam(placeholder)];
    [CFTextFields createNameTextField:&xValue yValue:&yValue width:&width height:&height placeholder:GetStringParam(placeholder) returnKey:GetStringParam(returnKey) autoCorr:GetStringParam(autoCorr) font:GetStringParam(font) fontSize:&fontSize];
}`

Here is the solution for still those who are looking for these options in keyboard(IOS/Android) https://github.com/mopsicus/UnityMobileInput