Questions tagged [phonegap-plugins]

A Cordova (PhoneGap) plugin bridges a bit of functionality between the WebView powering a Cordova application and the native platform the Cordova application is running on.

A Cordova (formerly PhoneGap, see ) plugin bridges a bit of functionality between the WebView powering a Cordova application and the native platform the Cordova application is running on. Plugins are composed of a single JavaScript interface used across all platforms, and native implementations following platform-specific plugin interfaces that the JavaScript will call into.

JavaScript

The entry point for any plugin is JavaScript. The reason developers use Cordova is so they can use and write JavaScript, not Objective-C, not Java, not C#. The JavaScript interface for your plugin is the front-facing and arguably most important part of your Cordova plugin.

You can structure your plugin’s JavaScript however you like. The one thing you must use to communicate between the Cordova JavaScript and native environments is the cordova.exec function. Here is an example:

cordova.exec(function(winParam) {}, function(error) {}, "service",
             "action", ["firstArgument", "secondArgument", 42, false]);

The parameters explained in more detail as follows:

  1. function(winParam) {} - Success function callback. Assuming your exec call completes successfully, this function will be invoked (optionally with any parameters you pass back to it)
  2. function(error) {} - Error function callback. If the operation does not complete successfully, this function will be invoked (optionally with an error parameter)
  3. "service" - The service name to call into on the native side. This will be mapped to a native class. More on this in the native guides below
  4. "action" - The action name to call into. This is picked up by the native class receiving the exec call, and, depending on the platform, essentially maps to a class's method. For more detail please check out the native guides located at the end of this article.
  5. [/* arguments */] - Arguments to get passed into the native environment

Native

Once you have defined a JavaScript for your plugin, you need to complement it with at least one native implementation.

For example, in , this native implementation would include doing the following:

  1. Creating a .h and .m class for the plugin
  2. Registering the class name in the Cordova.plist file
  3. Creating the function we called in the javascript as one of the instance methods of that class
  4. Handling our callback situations (if javascript expected a callback).

Further Reading

Links to learn more about the various platforms follow:

4204 questions
11
votes
2 answers

How can I set linker options for a Cordova plugin?

I am developing a Cordova plugin that uses a custom ios SDK framework. The framework depends on two binary libraries: libcurl.a and boost.a. Right now during development I install the plugin in a test application like this: cordova platform add…
Aras
  • 5,878
  • 9
  • 49
  • 76
11
votes
2 answers

How to make a custom private plugin in phonegap

Is there any way to achieve this? Everywhere I see contributing to plugin development or making use of an existing plugin (which are public). I would like to make a private plugin. Is this possible? I'm aware that through eclipse (for android) I can…
Alok Agarwal
  • 3,071
  • 3
  • 23
  • 33
11
votes
5 answers

still getting file not found error in xcode

I am new in PhoneGap, making a app via Xcode; But I found an error regarding CDVViewController.h. However, the file physically exists there. I am using Xcode 4.6 and Cordova 2.2.0.
Mohsin Qureshi
  • 151
  • 1
  • 1
  • 6
11
votes
4 answers

window.plugins undefined in cordova-2.0.0

I'm trying to use the BarcodeScanner plugin for Cordova in a BlackBerry device without luck. The sample code makes use of this structure: window.plugins.BarcodeScanner... but window.plugins is undefined. I tried with a fresh new application and…
Ivo
  • 8,172
  • 5
  • 27
  • 42
11
votes
3 answers

Phonegap Plugin:How to convert Base64 String to a PNG image in Android

Android does not allow native apps like Phonegap-based apps to write binary files. A common application is converting Base64 Strings to Images. So, how do you go about this problem?
mukama
  • 969
  • 2
  • 12
  • 28
10
votes
4 answers

Phonegap - Missing App Store Icon 1024x1024px App Store Icon

This is for PhoneGap. When submitting the .ipa with ApplicationLoader I'm getting this error: WARNING ITMS-90704: "Missing App Store Icon. iOS Apps must include a 1024x1024px App Store Icon in PNG format. Without providing the icon in the Asset…
Kamy D
  • 1,071
  • 2
  • 13
  • 23
10
votes
1 answer

Phonegap Build CLI-5.2.0 Download and Close From Within Web App

I've been wrestling with making calls to window open, using inappbrowser from within my app. Basically, I'm using phonegap as a wrapper to load up a mobile skinned CMS site with special app features. Here is the index.html. I'm using inappbrowser…
apoji187
  • 214
  • 3
  • 15
10
votes
1 answer

facebook app invite using ionic (cordova phonegap)

I would like to implement Facebook app invite into my mobile app so users can invite their friends to my app. I am using a hybrid framework called Ionic (cordova) but can't find any way to invite friends. There are Facebook plugins from ng-crodova…
10
votes
1 answer

Cordova, why would InAppBrowser plugin be required to open links in system browser

I have a Cordova app, it is a single page application with a single HTML file. All links should open in the system browser. I don't want an "embedded" InAppBrowser but really the native system / external browser. Everywhere we can find example of…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
10
votes
2 answers

How can I get WiFi Network information (SSID) in a Phonegap app?

I am making a Phonegap app. My requirement is to show different views to users depending on whether they are using a home network or a public network. Is there any plugin or any other way that can help to get the connected network information.…
Varun Nayyar
  • 887
  • 4
  • 20
  • 46
10
votes
3 answers

Errors upgrading cordova app

I'm trying to update a phonegap Android app from cordova 3.5.0 to cordova 5.1.1 because of security concerns. When I launch the app I get the following errors but I just can't understand where they come from.. Could you help me by suggesting where…
Surfer on the fall
  • 721
  • 1
  • 8
  • 34
10
votes
1 answer

Difference between FILE_URI and NATIVE_URI in cordova plugin camera

What is the different between FILE_URI and NATIVE_URI in cordova plugin camera?
10
votes
3 answers

How to Display PDF File with in the same App in phonegap

how to show Pdf file with in the same phonegap app. i tried Inappbrowser,Mupdf,PDFJS all are displaying PDF using other pdf viewer.i would like to open the pdf file with in the same app.Can anyone help me out.Thanks in advance
k.nagababu
  • 191
  • 1
  • 1
  • 5
10
votes
1 answer

What is cordova/argscheck used for?

I am trying to figure out what does cordova/argscheck do. I was not able to find any documentation that describes what is it used for nor how to use it. I managed to find its git repo however no comments are mentioned in the code. I have also taken…
thedethfox
  • 1,651
  • 2
  • 20
  • 38
10
votes
6 answers

Not able to launch a pdf file in inappbrowser in android

I have a requirement to show a pdf in inappbrowser when user clicks on a link. It is working fine in ios but not working on android. I am using IBM worklight for my project. Below is the code I have…