2015-05-25 22 views
1

我正在尝试在我的应用程序中包含Ionic Keyboard插件。我经历了Stack Overflow的几篇文章,并根据Idan的建议,将Ionic键盘插件类直接添加到IBM MobileFirst Platform Foundation 6.3项目中,就像我们在添加插件时一样。在MobileFirst中包含Ionic Keyboard Plugin

有没有人做过吗?我尝试过一次,但没有奏效。

事情我做:

  1. 新增的类文件IonicKeyboard.h,IonicKeyboard.m,UIWebViewExtension.h和UIWebViewExtension.m文件到classes文件夹。
  2. 在iOS环境中将以下条目添加到我的config.xml文件中。

    <feature name="Keyboard"> 
        <param name="ios-package" value="IonicKeyboard" onload="true" /> 
    </feature> 
    
  3. 尝试使用类hide-on-keyboard-show

    <div class="hide-on-keyboard-open"> 
        <div id="google-map"></div> 
    </div> 
    

但它没有工作,所以我假设键盘插件已无法正常工作。

+1

请提供您做了什么?分享代码。您使用的是什么MFP版本“6.3”或“7”? –

+0

对不起。 –

回答

3

为了添加IonicKeyboard到MobileFirst 6.3(在支持的方式),按照说明在documentation

  1. 声明插件在config.xml文件。

    <feature name="Keyboard"> 
        <param name="ios-package" onload="true" value="IonicKeyboard"/> 
    </feature> 
    
  2. 在JavaScript代码中使用cordova.exec()API。

    // added the cordova plugin definition in wlCommonInit(), as recommended by other answers I read (can't remember where), 
    // because the cordova event `deviceready` is fired and handled internally by MobileFirst 
    function wlCommonInit() { 
    
        // copied module id from https://github.com/driftyco/ionic-plugin-keyboard/blob/master/plugin.xml 
        cordova.define("com.ionic.keyboard.keyboard", function(require, exports, module) { 
        // copied code from https://github.com/driftyco/ionic-plugin-keyboard/blob/master/www/keyboard.js 
        var argscheck = require('cordova/argscheck'), 
         utils = require('cordova/utils'), 
         exec = require('cordova/exec'); 
    
        var Keyboard = function() { 
        }; 
    
        Keyboard.hideKeyboardAccessoryBar = function(hide) { 
         exec(null, null, "Keyboard", "hideKeyboardAccessoryBar", [hide]); 
        }; 
    
        Keyboard.close = function() { 
         exec(null, null, "Keyboard", "close", []); 
        }; 
    
        Keyboard.show = function() { 
         exec(null, null, "Keyboard", "show", []); 
        }; 
    
        Keyboard.disableScroll = function(disable) { 
         exec(null, null, "Keyboard", "disableScroll", [disable]); 
        }; 
    
        /* 
        Keyboard.styleDark = function(dark) { 
         exec(null, null, "Keyboard", "styleDark", [dark]); 
        }; 
        */ 
    
        Keyboard.isVisible = false; 
    
        module.exports = Keyboard; 
        }); 
        // Manually-register custom plugin 
        if (window.cordova && !window.cordova.plugins) { 
        window.cordova.plugins = {}; 
        } 
        // Do this instead of `clobbers` definition in native/www/default/worklight/cordova_plugins.js 
        window.cordova.plugins.Keyboard = cordova.require('com.ionic.keyboard.keyboard'); 
    
    } 
    
  3. 创建将在iOS中本机运行的插件类。 插件执行所需的操作并调用在调用cordova.exec()期间指定的JavaScript回调方法。发现https://github.com/driftyco/ionic-plugin-keyboard/tree/master/src/ios

    • IonicKeyboard.h
    • IonicKeyboard.m
    • UIWebViewExtension.h
    • UIWebViewExtension.m
  4. 将他们

    1. 将这些文件复制到该目录YourProject/apps/yourAppName/iphone/native/Classes/
+0

工作完美...感谢Nikki –

0

我可以做到这一点的唯一方法是使用Chris在问题中给出的解决方案。链接附件。 (它的一种方式) Add custom cordova plugin to IBM Worklight 6.1

但是这个解决方案存在严重的缺陷。它会在每次生成mfp时覆盖cordova_plugins.js文件和插件文件夹。

相关问题