如何检测是否从键盘的容器应用程序激活自定义键盘? [英] How to detect whether custom keyboard is activated from the keyboard's container app?
问题描述
我想知道是否有一种方法可以让我从键盘容器应用中检测 是否已在设备的设置应用中激活相关键盘。
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.
例如,我有兴趣在容器应用程序中添加一个简单的步骤功能,其中第1步将激活键盘,第2步将是偶然的在第1步完成。因此,我有兴趣弄清楚是否有办法检测键盘扩展是否被激活?
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?
谢谢!
推荐答案
这是我在我的一个项目中使用的方法。我认为这是你要求的,希望它可以帮助你。
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;
}
这篇关于如何检测是否从键盘的容器应用程序激活自定义键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!