0

I want to use a custom keyboard for UIWebView. Custom keyboard should be all HTML/JS/CSS in order to use for multiple device. For this reason I added a notification like bellow:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

In order to not allow the natural keyboard to comes up, I added following method when the notification is called.

- (void)keyboardWillShow
{
    [self.webViews endEditing:YES];
}

In HTML file I have:

<!DOCTYPE>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
    <title>keyboard</title>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
</head>  
<body>  

<div id="container">
    <textarea id="write"></textarea>
</div>
</body>  
</html>

The problem is, when I run this HTML file in UIWebView and have longpress on textarea, or double tap, it crashes the application. If I remove [self.webViews endEditing:YES]; It won't crash the app but it brings up the keyboard.

I suspected to "copy/paste/select All" options on UIWebView when the user double tap or long press on textarea. I tried to disable them but it didn't work. Any idea would be appreciated.

Hamid
  • 2,852
  • 1
  • 28
  • 45

3 Answers3

0

Customizing the keyboard needs a different approach.

There's a good explanation here including some code examples: Customizing the iOS keyboard

There's another thread here on SO with some discussion and links on the subject: How to create a custom keyboard

Community
  • 1
  • 1
Leijonien
  • 1,415
  • 14
  • 16
  • Custom keyboard should be all HTML/JS/CSS in order to use for multiple device. – Hamid Nov 19 '13 at 01:22
  • I know, follow the tutorial and use a UIWebView as custom view. – Leijonien Nov 19 '13 at 07:18
  • I looked at the tutorials and all of them was iOS code, but I need to design a custom keyboard by HTML/JS/CSS – Hamid Nov 19 '13 at 17:42
  • Yes, but see as 2 different steps. Step 1 would be to a create a custom keyboard **view** based on UIWebView. You'll need objective-C code to achieve that. Step 2 would be to load your custom HTML/JS/CSS keyboard in the webview (which you created in step 1). – Leijonien Nov 19 '13 at 18:34
  • I have created a keyboard like this tutorial: http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-keyboard-with-css-and-jquery/ I need to use it for any device, not only iOS. So the first step needs to be HTML/JS/CSS as well. – Hamid Nov 19 '13 at 18:42
  • That's fine, but that's only step 2. You would still need to customize the iOS keyboard interface to show your HTML keyboard (rather than trying to hide the iOS keyboard and show your own view). The tutorial shows how you can do that, you should be able to use a `UIWebView` instead. – Leijonien Nov 19 '13 at 19:46
  • inputView for UIWebView is readonly and I cannot assign a view for that. I don't have any textField. It's textarea in HTML. Both textare and keyboard are in one view. I wanted to do something like: `self.webView.inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];` but As I said it gives me the error that it's readonly property – Hamid Nov 19 '13 at 20:31
0

This is Apple Bug #15535639, I hope they fix it soon.

Hamid
  • 2,852
  • 1
  • 28
  • 45
0

Try this workaround, it worked for me.

- (void)keyboardWillShow
{

    dispatch_async(dispatch_get_main_queue(), ^{
    [self.webViews endEditing:YES];
    });
}