Adding a Custom Plug-in to the iOS Hybrid Web Container

An example plug-in class that allows access to the iOS network activity monitor is available in WorkFlow/Classes/Plugins.

  1. Copy the networkActivityMonitor.h and networkActivityMonitor.m files from WorkFlow/Classes/Plugins to the Workflow.xcodeproj project.
  2. Add the networkActivityMonitor.js to the Generated Workflow/<Workflow_Name>/html/js/ directory that corresponds with the Eclipse project that generated the Workflow.
  3. Modify Custom.js for any event desired to call the new plug-in.
    Here is an example that reacts to a menu item and uses a global variable to toggle the activity indicator on and off.:
    var gActIndicator = true; // global variable
    
    function customAfterMenuItemClick(screen, menuItem) {
    if (screen === "Start" && menuItem === "networkActivityIndicator") {
    window.plugins.networkActivityIndicator.set( gActIndicator, aiSuccess, aiFail );
    // Toggle the network activity indicator each time plugin is selected
    if ( gActIndicator )
    gActIndicator = false;
    else
    gActIndicator = true;
    return false;
    }
    }
    
    function aiSuccess() {
    alert("Successfully enabled activity indicator");
    }
    
    function aiFail() {
    alert("Failed to enable activity indicator");
    }
  4. Add a plug-in entry to PhoneGap.plist:
    Key: networkActivityIndicator
    Type: String
    Value: networkActivityIndicator
    
  5. Generate and deploy the Workflow application.
  6. Test the event in the Custom.js that is hooked into the new plug-in.
    If the plug-in requires additional resources, such as images or other files, these should be added to the project under the Resources group folder. For example, the ChildBrowser plug-in available at github.com contains icons that are stored in a file called ChildBrowser.bundle. In this example, the ChildBrowser.bundle should be added to the Resources group folder in the project in Xcode.
    Some plug ins also require files to be in a www/ directory. The notification.beep API is one example. If this is the case, add the resources to the www directory that is referenced by the project under the Resources group folder as described in Step 7 in Upgrading the PhoneGap Library used by the iOS Hybrid Web Container.