15

I was experimenting with how a custom keyboard affects my app. I installed Swype on my iPhone 6.

I find that in some of my views where I have custom inputView property set on a text field, the Swype keyboard is overriding and presenting instead of my picker. This completely breaks my UI and cannot be allowed.

Is there a way to explicitly tell iOS 8 only to use the inputView I have set?

Is this a bug, perhaps? It is not at all expected behavior to allow a third party to override my input spec?

Marcus Leon
  • 50,921
  • 112
  • 279
  • 413
Dean Davids
  • 4,154
  • 2
  • 27
  • 44
  • I am facing exact issue with my app. I have tried multiple custom keyboard but the problem is same everywhere. You have got any success ? – Tariq Jan 20 '15 at 11:14

4 Answers4

8

You can disable custom keyboard for your app with the following code:

include this in your app delegate:

- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier {
    if ([extensionPointIdentifier isEqualToString: UIApplicationKeyboardExtensionPointIdentifier]) {
        return NO;
    }
    return YES;
}
eertl
  • 351
  • 1
  • 9
  • Thanks. That is good to know and potentially a solution. A bit heavy handed though. Users may be frustrated to find their preferred keyboard missing from my app. There is no reason custom keyboards couldn't be used in many instances, only where I have provided a dedicated inputView is it a problem. – Dean Davids Oct 02 '14 at 13:50
  • I stumbled into this problem myself and this was the quicnk fix. My main problem is with a login view, where custom keyboards are not allowed to set passwords, so the password textfield never shows the keyboard when the user hits "next" from the username field. (so if you also have a login or a secure text entry textfield, test that out with swype to see that doesn't break your UI as well) – eertl Oct 03 '14 at 15:06
  • @eertl: I have another problem. I know that we will be able to disable custom iOS 8 keyboards using above code snippet. The important point here is that we need to use Xcode-6/iOS 8 SDK to use the above. I am still on Xcode 5 due to some other limitations. Is there any way I can prevent the third party keyboards using iOS 7 SDK/Xcode 5? Please Help. – Rashmi Ranjan mallick Oct 29 '14 at 13:57
  • 1) The above answer is what you asked first time @DeanDavids , you can accept it :) 2) The third party keyboard it will not work if you use Xcode 5 and SDK7 – TonyMkenu Oct 30 '14 at 15:14
  • @TonyMkenu my desire was more towards preventing override of the inputView or, more specifically, custom picker for individual textfields. This actually seems to have been fixed in released iOS8 versions so no longer an issue. I would accept the answer aside for the side effects of disabling users choice entirely which I would not find acceptable. – Dean Davids Oct 30 '14 at 15:57
4

Using the answer from Pablo Ezequiel Romero as a starting point, I was able to get things to work for me. Essentially, rather than using a UIViewController for the custom keyboard, use a UIInputViewController and put your controls inside the UIInputViewController's inputView. Then, assign the inputView of your UITextField or UITextView to the inputView of the UIInputViewController.

If you're using auto layout, you need to make sure that you set everything properly and make sure to set an initial height constraint on the inputView and set its priority below the max 999 level (I used 800). Any height will do; the system will replace your constraint with one of its own. The lower priority avoids auto layout conflicts. (For me, if I didn't include this constraint, the final view wouldn't have any height at all.)

When I did all this, I was able to switch in and out of my (internal to the app) custom keyboard and any third-party keyboard extension.

Craig Pearlman
  • 1,836
  • 1
  • 12
  • 4
4

Swift 4

  func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplicationExtensionPointIdentifier) -> Bool {
        if (extensionPointIdentifier == .keyboard) {
            return false
        }
        return true
    }
uplearnedu.com
  • 2,966
  • 4
  • 36
  • 54
2

I had a similar issue and I was able to fix it using UIInputViewController. Basically the view that I set in inputView is the view of my UIInputViewController subclass. I was using UIViewController, but after replacing the base view controller it started to work well.

  • Pablo, I never have fully resolved this issue. Can be a bit more clear. I do not understand, precisely, what you did. – Dean Davids Mar 05 '16 at 11:51