How to Detect Whether Custom Keyboard Is Activated from the Keyboard's Container App

How to detect whether custom keyboard is activated from the keyboard's container app?

Here is a method I have used in one of my projects. I think it is what you asked for, hope it helps you.

- (BOOL)isCustomKeyboardEnabled {
NSString *bundleID = @"com.company.app.customkeyboard"; // Replace this string with your custom keyboard's bundle ID
NSArray *keyboards = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:@"AppleKeyboards"]; // Array of all active keyboards
for (NSString *keyboard in keyboards) {
if ([keyboard isEqualToString:bundleID])
return YES;
}

return NO;
}

How can I check does my ios8 custom keyboard extension have open access?

There is no API, but if you have app group access enabled, you can try to check if you are able to read/write to the folder. It should give you a permission error access is not enabled.

Custom iOS keyboard accesses container without Full Access privileges

At some point between iOS 8.0 and 9.0 (I want to say 8.3, but I can't remember the exact version) Apple changed the restrictions on custom keyboards so that they had read-only access to the shared container -- both the file system and the NSUserDefaults associated with it, even when full access is disabled.

The documentation hasn't been updated yet. You should file a radar.

Programmatically detecting / changing custom keyboards

This assumes you want the list of keyboards setup in the Settings app under General, Keyboards.

  1. You can determine the primary keyboard:

    UITextInputMode *currentMode = [[UITextInputMode activeInputModes] firstObject];
  2. You can determine the possible keyboards

    NSArray *possibleModes = [UITextInputMode activeInputModes];
  3. You can determine when the keyboard changes. This is done by listening for the UITextInputCurrentInputModeDidChangeNotification notification.

  4. However, there is no API to change the keyboard.

So you can do everything you need except the most important part.



Related Topics



Leave a reply



Submit