1

How can I tell which third party keyboard the user is using or switching to?

I did not find any notification or API that I could use to check this info.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Gin
  • 1,763
  • 3
  • 12
  • 17

2 Answers2

0

You can't know which keyboards are installed, nor can you decide which keyboard to load next.

Apple's documentation states:

To ask the system to switch to another keyboard, call the advanceToNextInputMode method (..) The system picks the appropriate “next” keyboard; there is no API to obtain a list of enabled keyboards or for picking a particular keyboard to switch to.

For further information, read Apple's Custom Keyboards API Documentation: https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html#//apple_ref/doc/uid/TP40014214-CH16-SW21

nurnachman
  • 4,468
  • 2
  • 37
  • 40
  • 1
    thanks for the answer. But I believe Apple must have a way to see the list of keyboards on their side. Just wondering there might be some hacky way to achieve this. – Gin Oct 03 '14 at 23:54
  • If there were, you couldn't use it in a submitted app. That's against the rules. – Ruben Martinez Jr. Apr 13 '15 at 23:28
0

A bit late but you can get the list of active keyboards on a device. All keyboard identifiers are stored in UserDefaults and here is how you can get them:

/**

 - Author:
 Panayot Panayotov

 - returns:
 True or False

 - Important:
 Result is returned immediately after non system identifier is found

 This method iterates through all public keyboard identifiers and
 evaluates a regex that matches system keyboards
 [
     "nb_NO@sw=QWERTY-Norwegian;hw=Automatic",
     "zh_Hant-Zhuyin@sw=Zhuyin;hw=Automatic",
     "ur@sw=Urdu;hw=Automatic",
     "zh_Hant-HWR@sw=HWR-Traditional",
     "zh_Hant-Pinyin@sw=Pinyin10-Traditional;hw=Automatic",
     "emoji@sw=Emoji"
 ]
 */
-(BOOL)hasUnkownKeyboard {

    NSString * appleKeyboardsRegexp = @"^(?:[0-9a-zA-Z_\\-]+)(?:@sw|@hw)[0-9a-zA-Z_\\-\\-;=]*$";
    NSPredicate * appleKeyboardsTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", appleKeyboardsRegexp];
    NSArray *keyboards = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"AppleKeyboards"];

    for (NSString *keyboard in keyboards) {
        if(![appleKeyboardsTest evaluateWithObject:keyboard]){
            return YES;
        }
    }

    return NO;
}
Pancho
  • 4,099
  • 1
  • 21
  • 32