Book Image

PhoneGap 4 Mobile Application Development Cookbook

Book Image

PhoneGap 4 Mobile Application Development Cookbook

Overview of this book

Table of Contents (19 chapters)
PhoneGap 4 Mobile Application Development Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Extending your Cordova iOS application with a native plugin


How to do it...

In this recipe, we will create a native iOS plugin for our Cordova application using command-line tools, as suggested by Cordova. We will implement the plugin for Android that we created in the previous recipe to work with iOS:

  1. Change the working project to helloplugin, open plugin.xml, and add information about the new iOS platform:

      <platform name="ios">
    
        <config-file target="config.xml" parent="/widget">
          <feature name="Hello">
            <param name="ios-package" value="HWPHello" />
          </feature>
        </config-file>
    
        <header-file src="src/ios/HWPHello.h" target-dir="HelloPlugin"/>
        <source-file src="src/ios/HWPHello.m" target-dir="HelloPlugin"/>
      </platform>
    
    </plugin>
  2. Then create two blank files, HWPHello.h and HWPHello.m, inside the src/ios directory. Both files will contain our native Objective-C code for the iOS platform.

  3. Open HWPHello...