3

I'm currently trying to figure out how to detect when keys are being pressed on a keyboard in an iOS application. The problem is that the input boxes and textfields are apart of HTML in the UIWebView. I know you can check if the keyboard has been shown or hidden, but i seem not to be able to get the key presses to register as a touch event. I know there is the way of using javascript to pick up the events.

for example

JavaScript:

$(function(){
   $('input, textarea').keypress(function() {
      window.location = "randomURL://fakeURL";
   });
});

XCode:

NSURL *url = request.URL;
if([[url scheme] isEqualToString:@"randomURL"]) {
   NSLog(@"Key Pressed");
   return NO;
}

I'm just wondering if there is a way of doing it natively and not use the javascript as i would have to add the javascript to multiple files.

If anyone needs help with the javascript method of doing this. Just message me and i'll help you out. I just hope so one will be able to help with a native method of doing this.

YaBCK
  • 2,949
  • 4
  • 32
  • 61
  • Have a look at this http://stackoverflow.com/questions/15537320/invoke-method-in-objective-c-code-from-html-code-using-uiwebview and this might give you some clues http://stackoverflow.com/questions/9826792/how-to-invoke-objective-c-method-from-javascript-and-send-back-data-to-javascrip – sbarow Mar 12 '14 at 12:26
  • @sbarow The links you've posted are exactly what i'm already doing. I'm trying to find out if there is a native way of doing it instead of calling the javascript. As i have to include the javascript file in multiple pages. – YaBCK Mar 12 '14 at 12:31

0 Answers0