在MobileFirst中包含Ionic Keyboard插件

时间:2015-05-25 15:15:38

标签: ionic ibm-mobilefirst

我想在我的应用程序中包含Ionic Keyboard插件。我在Stack Overflow上发了几篇帖子,根据Idan的一个答案,他建议将Ionic Keyboard Plugin Classes直接添加到IBM MobileFirst Platform Foundation 6.3项目中,就像我们在添加插件时一样。

有没有人这样做过?我尝试过一次,但它不起作用。

我做的事情:

  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>
    
  4. 但它没有用,所以我假设键盘插件无法正常工作。

2 个答案:

答案 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回调方法。

    1. 复制https://github.com/driftyco/ionic-plugin-keyboard/tree/master/src/ios中找到的文件
      • IonicKeyboard.h
      • IonicKeyboard.m
      • UIWebViewExtension.h
      • UIWebViewExtension.m
    2. 将它们放入目录YourProject/apps/yourAppName/iphone/native/Classes/

答案 1 :(得分:0)

我能做到这一点的唯一方法是使用克里斯在问题中给出的解决方案。链接附件。 (它在某种程度上是一种黑客行为) Add custom cordova plugin to IBM Worklight 6.1

但这个解决方案存在严重缺陷。每次发生mfp构建时,它都会覆盖cordova_plugins.js文件和plugins文件夹。