我可以为我的应用禁用自定义键盘(iOS8)吗?

时间:2014-07-03 15:09:27

标签: ios ios8

编辑:tl; dr - 有可能,请参阅下面接受的答案。

是否有任何(不仅是编程)方法阻止自定义键盘(iOS8)用于我的应用程序?我主要对“每个应用程序”设置感兴趣,因此我的应用程序不允许使用自定义键盘,但在系统范围内禁用自定义键盘是最后的选择。

到目前为止,我知道自定义键盘是系统范围的,可以被任何应用程序使用。只有安全文本输入(secureTextEntry设置为YES的文本字段),操作系统才会回退到库存键盘。这里没什么希望。

我从App Extension Programming Guide得到一个印象,MDM(移动设备管理)可以限制设备使用自定义键盘,但我没有在Apple Configurator.app的新测试版中找到该选项OS X Yosemite。 “Configurator”是否缺少该选项?

这里有什么想法吗?我应该提交一份雷达来暗示Apple应该推出这样的功能吗?

4 个答案:

答案 0 :(得分:47)

看起来你在beta种子3中得到了你想要的东西3. UIApplication.h的第440行:

// Applications may reject specific types of extensions based on the extension point identifier.
// Constants representing common extension point identifiers are provided further down.
// If unimplemented, the default behavior is to allow the extension point identifier.
- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier NS_AVAILABLE_IOS(8_0);

它目前没有包含在文档中,但听起来它会完全按照您的要求进行操作。

我猜这些“扩展点标识符”不是扩展名的唯一标识符,而是它们的类型,因为第545行还有这个:

// Extension point identifier constants
UIKIT_EXTERN NSString *const UIApplicationKeyboardExtensionPointIdentifier NS_AVAILABLE_IOS(8_0);

TLDR :要禁用自定义键盘,您需要在应用代理中包含以下内容:

- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier {
    if ([extensionPointIdentifier isEqualToString: UIApplicationKeyboardExtensionPointIdentifier]) {
        return NO;
    }
    return YES;
}

答案 1 :(得分:10)

斯威夫特3:

func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplicationExtensionPointIdentifier) -> Bool {
    if extensionPointIdentifier == UIApplicationExtensionPointIdentifier.keyboard {
        return false
    }
    return true
}

答案 2 :(得分:3)

我只想为希望在Xamarin iOS中实现此方法的开发人员添加此功能。我们的想法是覆盖ShouldAllowExtensionPointIdentifier中的AppDelegate方法:

public override bool ShouldAllowExtensionPointIdentifier(UIApplication application, NSString extensionPointIdentifier)
{
    if (extensionPointIdentifier == UIExtensionPointIdentifier.Keyboard) 
    {           
        return false;
    }
    return true;
}

答案 3 :(得分:1)

在Swift 5中,UIApplicationExtensionPointIdentifier更改为UIApplication.ExtensionPointIdentifier。

func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplication.ExtensionPointIdentifier) -> Bool {
    if extensionPointIdentifier == UIApplication.ExtensionPointIdentifier.keyboard {
        return false
    }
    return true
}
相关问题