Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

ios - Can I disable custom keyboards (iOS8) for my app?

EDIT: tl;dr - it is possible, see accepted answer below.

Is there any (not only programatic) way of preventing custom keyboards (iOS8) from being used for my application? I am mainly interested in "per-app" setting, so just my app is not allowed to use custom keyboards, but disabling custom keyboards system-wide is last resort.

So far I know that custom keyboards are system-wide and can be used by any application. The OS will fallback to stock keyboard only for secure text entry (text fields with secureTextEntry set to YES). Not much hope here.

I got an impression from App Extension Programming Guide that MDM (Mobile Device Management) can restrict device from using custom keyboards at all, but I didn't find that option in the new beta version of Apple Configurator.app for OS X Yosemite. Is 'Configurator' just missing that option?

Any ideas here? Should I file a radar to suggest that Apple should introduce such functionality?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like you got what you wanted in beta seed 3. Line 440 of UIApplication.h:

// 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);

It's not currently included in the docs, but sound like it will do exactly what you asked here.

I'm guessing these "extension point identifiers" are not unique identifiers of extensions, but of their types, as there is also this on line 545:

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

TLDR: to disable custom keyboards you would include something like this in your app delegate:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...