在phonegap中打开软键盘时,showkeyboard / hidekeyboard事件不会在ios 7上触发

我有一个非常简单的代码,只是为了在软键盘打开时尝试发出警报。 我只是想确定这是一个显示键盘打开的可行方法。

document.addEventListener('deviceready', function () { $.app.deviceReady(); document.addEventListener("showkeyboard", function(){ alert("Keyboard is ON");}, false); document.addEventListener("hidekeyboard", function(){ alert("Keyboard is OFF");}, false); }, false); 

这些事件永远不会在IOS上触发。 只有android。 我确实看到有一个插件在IO7上有助于这个,但我现在根本找不到它。

我正在使用PG 3.1.0和PG Build

编辑:我只想强调这是针对Phonegap Build ,这意味着据我所知,我不会使用任何自定义插件。 只有这里列出的那些: https : //build.phonegap.com/plugins

我也遇到了同样的问题。 没有可用的插件。 最后我为iOS添加了新的插件方法。

在您的应用程序上添加CDVNotification插件,并添加以下方法和属性。

CDVNotification.h

 @property (strong) NSString* keyboardShowcallbackId; @property (strong) NSString* keyboardHidecallbackId; - (void)keyboardShow:(CDVInvokedUrlCommand*)command; - (void)keyboardHide:(CDVInvokedUrlCommand*)command; 

CDVNotification.m

 //Keyboard notifications. - (void)keyboardShow:(CDVInvokedUrlCommand*)command { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; self.keyboardShowcallbackId = command.callbackId; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardShowCallback:) name:UIKeyboardWillShowNotification object:nil]; } - (void)keyboardHide:(CDVInvokedUrlCommand*)command { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; self.keyboardHidecallbackId = command.callbackId; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardHideCallback:) name:UIKeyboardWillHideNotification object:nil]; } - (void)keyBoardHideCallback:(NSNotification*)notification { if (self.keyboardHidecallbackId) { CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [result setKeepCallbackAsBool:YES]; [self.commandDelegate sendPluginResult:result callbackId:self.keyboardHidecallbackId]; } } - (void)keyBoardShowCallback:(NSNotification*)notification { if (self.keyboardShowcallbackId) { CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [result setKeepCallbackAsBool:YES]; [self.commandDelegate sendPluginResult:result callbackId:self.keyboardShowcallbackId]; } } 

您可以在打开时获取回调并使用以下代码隐藏键盘。

  cordova.exec(function(){alert("Keyboard is ON");},function(){alert("error");},"Notification","keyboardShow",[]); cordova.exec(function(){alert("keyboard is OFF");},function(){alert("error");},"Notification","keyboardHide",[]);