Search code examples
cordova-pluginsibm-mobilefirst

Not able to call window.plugins in IBM MobileFirst 6.3


I am using MobileFirst 6.3. I am not able to call window.plugins.XXX (i want to use SSLcertificateChecker as XXX) . But the window.plugins is coming as undefined.

I want to include SSLCertificateChecker phonegap plugin from https://github.com/EddyVerbruggen/SSLCertificateChecker-PhoneGap-Plugin into my worklight project.

  1. First i tried iOS. I am adding manually all files.

  2. Added

    <feature name="SSLCertificateChecker">
        <param name="ios-package" value="SSLCertificateChecker" />
    </feature> in config.xml
  1. Add a dependency to Security.framework and also copied SSLCertificateChecker.* to plugin folder

But during implementation window.plugins comes undefined. Not a able to proceed.


Solution

  • It should work by following the same instructions I have provided in this answer, just adjusted to yours.

    Note: The same warnings I have written there apply here as well. Namely: on each build performed in MobileFirst Studio the file cordova_plugins.js is being re-generated, thus you will lose the required changes that you will perform in this file, and you will be required to re-do them over and over again.

    One possible solution to that is to upgrade to the soon-to-be released MobileFirst Platform Foundation 7.1, which introduces support for another class of application type - Cordova applications, with MobileFirst SDK integrated as a plug-in, thus enabling you to use Cordova Plug-man (or any other method) to install 3rd party plug-ins as you would in any Cordova-based application. Cordova Plug-man is not supported in releases prior to 7.1. Otherwise, you'll just have to find build hacks around it.


    Studio

    config.xml

    1. Add the plug-in declaration to your-app\iphone\native\config.xml

    index.html

    1. Add the following to the header element:

      <script type="text/javascript" src="js/SSLCertificateChecker.js"></script>
      

    SSLCertificateChecker.js

    1. Make sure to place the SSLCertificateChecker.js file in the your-app\common\js folder.

    2. Edit the file.

      • Add at the top:

        cordova.define("nl.x-services.plugins.SSLCertificateChecker", function(require, exports, module) {
        
      • Add at the bottom: });

    Build

    1. Build the project in MobileFirst Studio and open it in Xcode

    Xcode

    1. In Build Phases add the required Security.framework (but it will most likely already be there)

    2. Right-click on the project root folder, select "Add Files to..." and copy over the provided .h and .m files

    3. Navigate to native\www\default\worklight\cordova_plugins.js and add the following. This is also the file you will have to re-edit each time you make a build in MobileFirst Studio...

      {
          "file": "../js/SSLCertificateChecker.js",
          "id": "nl.x-services.plugins.SSLCertificateChecker",
          "clobbers": [
              "window.plugins.sslCertificateChecker"
          ]
      },
      
    4. Run on iOS Simulator or device.