Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

keyboard

ios8

I was wondering if there is a method that would allow me to detect from the keyboard container app whether the associated keyboard has been activated in the the device's Settings app.

For example, I am interested in adding a simple "steps" feature inside the container app where step 1 would be "activate the keyboard", and step 2 would be contingent on step 1's completion. As such, I am interested in figuring out whether there is a way to detect whether the keyboard extension is activated?

Thanks!

like image 563
daspianist Avatar asked Sep 04 '14 21:09

daspianist


People also ask

How do I enable a custom keyboard?

Here is a summary: Go to Android Settings > Languages and input > Current keyboard > Choose keyboards. You should see your Custom Keyboard on the list. Enable it.


2 Answers

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; } 
like image 176
Kurt Avatar answered Oct 05 '22 04:10

Kurt


Just in case here is Swift version of Kurt's brilliant and awesome answer:

   func isKeyboardExtensionEnabled() -> Bool {     guard let appBundleIdentifier = Bundle.main.bundleIdentifier else {         fatalError("isKeyboardExtensionEnabled(): Cannot retrieve bundle identifier.")     }      guard let keyboards = UserDefaults.standard.dictionaryRepresentation()["AppleKeyboards"] as? [String] else {         // There is no key `AppleKeyboards` in NSUserDefaults. That happens sometimes.         return false     }      let keyboardExtensionBundleIdentifierPrefix = appBundleIdentifier + "."     for keyboard in keyboards {         if keyboard.hasPrefix(keyboardExtensionBundleIdentifierPrefix) {             return true         }     }      return false } 
like image 35
Valentin Shergin Avatar answered Oct 05 '22 06:10

Valentin Shergin