3

I do not want an external keyboard to be allowed in my app. I realize this is an edge case but I do not like how the keyboard will not be shown when an external keyboard is used. Especially because I have a custom view above the keyboard that will now be shown at the bottom of the screen. Also, I have textfields that should only require numbers (phonenumber for example). Instead of checking input, I would rather just show the numbers keyboard. Obviously this can't happen with external keyboard.

I saw a post here: How to detect external keyboard connectification in objective-c?

but that's not enough to just detect it...I want to disable!

Thanks,

-Adam

Community
  • 1
  • 1
aelstonjones
  • 382
  • 2
  • 8
  • 25

3 Answers3

3

This seems to be a sloppy way of handling input. Do proper input checking and validation, rather than trying to force a single input method. What if someone tries to use the iOS copy/paste functionality on your field? What if there is some future update that provides another input method that you were not anticipating?

wmorrell
  • 4,988
  • 4
  • 27
  • 37
2

Don't do this. It's wrong. Your users who prefer external keyboards will hate you, will send you bug reports, and will write bad reviews of your app. As if that's not enough, this is probably grounds for your app being rejected by Apple when you submit it.

Jiva DeVoe
  • 1,338
  • 1
  • 9
  • 10
0

Here are two things you can do to circumvent this problem:

You can force the keyboard to appear even when there is an external keyboard present.

You can validate text input using the UITextField delegate method

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

For example, to allow only numbers to be entered, you can do:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

    NSCharacterSet *myCharSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];

    if ([[string stringByTrimmingCharactersInSet:myCharSet] length]) {
        return YES;
    } else {
        return NO;
    }
} 
PengOne
  • 48,188
  • 17
  • 130
  • 149